Pagini recente » Cod sursa (job #2030338) | Cod sursa (job #2690704) | Cod sursa (job #2509928) | Cod sursa (job #1741147) | Cod sursa (job #1213603)
program betisoare;
var n,i,j,l,r,ans:longint;
a:array[1..800] of longint;
procedure sort(l,r: longint);
var
i,j,x,y: longint;
begin
i:=l;
j:=r;
x:=a[(l+r) div 2];
repeat
while a[i]<x do
inc(i);
while x<a[j] do
dec(j);
if not(i>j) then
begin
y:=a[i];
a[i]:=a[j];
a[j]:=y;
inc(i);
j:=j-1;
end;
until i>j;
if l<j then
sort(l,j);
if i<r then
sort(i,r);
end;
function cbin2(l,r,val:longint):longint;
var m:longint;
begin
if l=r then cbin2:=l else
begin
m:=(l+r)div 2;
if a[m+1]<=val then cbin2:=cbin2(m+1,r,val)
else cbin2:=cbin2(l,m,val);
end;
end;
begin
assign(input,'nrtri.in');
reset(input);
assign(output,'nrtri.out');
rewrite(output);
readln(n);
for i:=1 to n do read(a[i]);
sort(1,n);
for i:=1 to n-2 do
for j:=i+1 to n-1 do
begin
if a[n]<=a[i]+a[j] then r:=n else r:=cbin2(1,n,a[i]+a[j]);
l:=j+1;
if l<=r then ans:=ans+r+1-l;
end;
writeln(ans);
close(output);
end.