Cod sursa(job #156859)

Utilizator valytgjiu91stancu vlad valytgjiu91 Data 12 martie 2008 19:34:02
Problema Bilute Scor 50
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.71 kb
var f,g:text;
a:array[1..30000] of record
              x,y:byte;
              end;
v:array[1..30000] of longint;
n,i,j:integer;
max:longint;
begin
assign(f,'bilute.in');
reset(f);
readln(f,n);
for i:=1 to n do
     readln(f,a[i].x,a[i].y);
close(f);
max:=2000000000;
for i:=1 to n do
begin
    for j:=1 to n do
       begin
       if (j<>i) then
             v[i]:=v[i]+((a[j].x*a[j].y)+(a[j].x*abs(j-i)));
       if v[i]>max then break;
       end;
   if v[i]<max then max:=v[i];
   end;
j:=1;
for i:=2 to n do
   if max=v[i] then begin
                     j:=i;
                     break;
                     end;
assign(g,'bilute.out');
rewrite(g);
write(g,j,' ',max);
close(g);
end.