Cod sursa(job #6515)

Utilizator ProtomanAndrei Purice Protoman Data 19 ianuarie 2007 22:19:39
Problema Numarare triunghiuri Scor 45
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.3 kb
var f1,f2:text; i,j,g,n,m,p,q:longint; x:longint; a:array[1..800] of integer;
begin
        assign(f1,'nrtri.in');
        reset(f1);
        assign(f2,'nrtri.out');
        rewrite(f2);
        read(f1,n);
        for i:=1 to n do
        read(f1,a[i]);
        for i:=1 to n do
        for j:=i+1 to n do
        for g:=j+1 to n do
        begin
                if (a[i]>a[j])and(a[i]>a[g]) then
                begin
                        m:=a[i];
                        if a[j]>a[g] then begin p:=a[j]; q:=a[g]; end
                                     else begin q:=a[j]; p:=a[g]; end;
                end;
                if (a[j]>a[i])and(a[j]>a[g]) then
                begin
                        m:=a[j];
                        if a[i]>a[g] then begin p:=a[i]; q:=a[g]; end
                                     else begin q:=a[i]; p:=a[g]; end;
                end;
                if (a[g]>a[j])and(a[g]>a[i]) then
                begin
                        m:=a[g];
                        if a[j]>a[i] then begin p:=a[j]; q:=a[i]; end
                                     else begin q:=a[j]; p:=a[i]; end;
                end;
                if (g<>i) and (g<>j) then if not(p+q<m) then inc(x);

        end;
        write(f2,x);
        close(f1);
        close(f2);
end.