Pagini recente » Cod sursa (job #993929) | Cod sursa (job #1963009) | Cod sursa (job #1573735) | Cod sursa (job #3138238) | Cod sursa (job #41124)
Cod sursa(job #41124)
var f:text;i,j,l,x,y,s,n,z:longint;a:array[1..1000]of longint;
begin
assign(f,'nrtri.in');reset(f);read(f,n);
for i:=1 to n do read(f,a[i]);close(f);
for i:=1 to n-1 do for j:=i+1 to n do
if a[i]>a[j] then begin x:=a[i];a[i]:=a[j];a[j]:=x;end;
a[n+1]:=(a[n]+a[n-1])*2;
for i:=1 to n-2 do for j:=i+1 to n-1 do
begin
x:=j+1;y:=n;l:=j;z:=0;
while(x<=y)do
begin
l:=(x+y)div 2;
if(a[l]<=a[i]+a[j])and(a[l+1]>a[i]+a[j])then begin z:=1;break;end;
if(a[l]<=a[i]+a[j])and(a[l+1]<=a[i]+a[j])
then x:=l+1 else if x<y then y:=l else break;
end;
if z=1 then s:=s+l-j;
end;
assign(f,'nrtri.out');rewrite(f);write(f,s);close(f);
end.