Pagini recente » Cod sursa (job #2481206) | Cod sursa (job #2717820) | Cod sursa (job #2178795) | Cod sursa (job #1863018) | Cod sursa (job #1213591)
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
x:=(l+r)div 2;
i:=l;j:=r;
while i<=j do
begin
while a[i]<a[x] do inc(i);
while a[j]>a[x] do dec(j);
if i<=j then
begin
y:=a[i];
a[i]:=a[j];
a[j]:=y;
inc(i);
dec(j);
end;
end;
if j>l 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.