Cod sursa(job #254355)
| Utilizator | Data | 7 februarie 2009 11:28:05 | |
|---|---|---|---|
| Problema | Cuburi2 | Scor | 20 |
| Compilator | fpc | Status | done |
| Runda | Stelele Informaticii 2009, clasele 9-10, ziua 2 | Marime | 0.44 kb |
var a:array[1..100000]of longint;
i,j,l,max,s,poz,n,m,x,y:longint;
f,g:text;
begin
assign(f,'cuburi2.in');reset(f);
assign(g,'cuburi2.out');rewrite(g);
readln(f,n,m);
for i:=1 to n do read(f,a[i]);
for i:=1 to m do begin
readln(f,x,y);
max:=maxlongint;poz:=0;
for j:=x to y do begin
s:=0;
for l:=x to y do s:=s+(abs(l-j)*a[l]);
if s<max then begin
poz:=j;max:=s;end;
end;
writeln(g,poz,' ',max);
end;
close(f);
close(G);
end.