Pagini recente » Diferente pentru implica-te/arhiva-educationala intre reviziile 166 si 165 | Cod sursa (job #843249) | Cod sursa (job #256815) | Cod sursa (job #2332494) | Cod sursa (job #1108388)
var i,j,x,k,n:longint;
a:array[1..802] of longint;
buf1,buf2:array[1..1 shl 16] of char;
procedure swap(var a,b:longint);
var aux:longint;
begin
aux:=a;
a:=b;
b:=aux;
end;
procedure qsort(left,right:longint);
var i,j,pivot:longint;
begin
i:=left; j:=right; pivot:=a[((left+right) div 2)+1];
repeat
while a[i]<pivot do inc(i);
while a[j]>pivot do dec(j);
if i<=j then begin
swap(a[i],a[j]);
inc(i);
dec(j);
end;
until i>j;
if i<right then qsort(i,right);
if j>left then qsort(left,j);
end;
begin
assign(input,'nrtri.in');
assign(output,'nrtri.out');
reset(input);
rewrite(output);
settextbuf(input,buf1);
settextbuf(output,buf2);
readln(n);
for x:=1 to n do
read(a[x]);
qsort(1,n);
for i:=1 to n-2 do
for j:=i+1 to n-1 do
begin
x:=j+1;
while (a[i]+a[j]>=a[x]) and (x<=n) do
inc(x);
inc(k,x);
dec(k,j+1);
end;
writeln(k);
close(input);
close(output);
{Totusi este trist in lume}
end.