Cod sursa(job #62849)

Utilizator FreeYourMindAndrei FreeYourMind Data 24 mai 2007 14:45:27
Problema Numarare triunghiuri Scor 45
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.92 kb
Program NumarareTriunghiuri;

const fin = 'nrtri.in';
     fout = 'nrtri.out';

var n: word;
    b: array[1..800] of word;
    c: array[1..61000] of word;
  ANS: longint;

procedure load;
 var f: text; i: word;
begin
 assign(f, fin); reset(f);

  fillchar(c, sizeof(c), 0);

  readln(f, n);
  for i:=1 to n do
      begin
       read(f, b[i]);
       inc(c[b[i]]);
      end;

 close(f);
end;

function max(a,b: longint): longint;
begin
 if a>b then max:=a else max:=b;
end;

procedure solve;
 var i,j: word;
begin
 for i:=2 to 60000 do
     c[i]:=c[i]+c[i-1];

 ANS:=0;
 for i:=1 to n-1 do
     for j:=i+1 to n do
         begin
          ANS:=ANS+c[ b[i]+b[j] ] - c[ max(b[i],b[j])-1]-1;
          if b[i]=b[j] then dec(ANS);
         end;
end;

procedure save;
 var f: text;
begin
 assign(f, fout); rewrite(f);
 write(f, ANS);
 close(f);
end;

begin
 load;
 solve;
 save;
end.