Pagini recente » Cod sursa (job #2710216) | Cod sursa (job #2430139) | Cod sursa (job #704781) | Cod sursa (job #1665650) | Cod sursa (job #96522)
Cod sursa(job #96522)
var
fi, fo : text;
i, j, n, aux, nt, l12, k, s, d, m : longint;
a : array[1..800] of integer;
begin
assign(fi,'nrtri.in'); reset(fi);
assign(fo,'nrtri.out'); rewrite(fo);
readln(fi,n);
for i := 1 to n do
read(fi,a[i]);
for i := 1 to n-1 do
for j := i+1 to n do
if a[i] > a[j] then
begin
aux := a[i]; a[i] := a[j]; a[j] := aux;
end;
for i := 1 to n-2 do
for j := i+1 to n-1 do
begin
l12 := a[i]+a[j]; // suma lungimilor primelor 2 segmente
s := j; d := n; // Cautam cel mai mare indice pentru care l12 >= a[m].
repeat
m := (s+d) div 2;
if l12 >= a[m] then
s := m
else
d := m
until d-s <= 1;
if l12 >= a[m+1] then
inc(m);
inc(nt,m-j);
end;
write(fo,nt);
close(fi); close(fo);
end.