Pagini recente » Cod sursa (job #181025) | Cod sursa (job #3123020) | Cod sursa (job #1255885) | Cod sursa (job #1315068) | Cod sursa (job #1135159)
Program triunghiuri;
var V : array [1..900] of longint;
b1,b2 :array[0..1 shl 17 ] of char;
n,i,l,j,m : longint;
procedure swap(var x,y:longint);
var aux:longint;
begin
aux:=x;
x:=y;
y:=aux;
end;
procedure qsort(left,right:longint);
var i,j,pivot:longint;
begin
i:=left; j:=right; pivot:=V[((right+left) div 2)];
repeat
while V[i]<pivot do inc(i);
while V[j]>pivot do dec(j);
if i<=j then begin
swap(V[i],V[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'); settextbuf(input,b1); reset(input);
assign(output,'nrtri.out'); settextbuf(output,b2); rewrite(output);
readln(n); l:=0;
for i:=1 to n do read(V[i]);
qsort(1,n);
for i:=1 to n-2 do
for j:=i+1 to n-1 do begin
m:=j+1;
while (V[m]<=(V[i]+V[j])) and (m<=n) do
begin
l:=l+1;
m:=m+1;
end;
end;
writeln(l);
close(input);
close(output);
end.