Pagini recente » Rating Ioan Doros (neludoros) | Cod sursa (job #519198) | Cod sursa (job #1846599) | Cod sursa (job #2547251) | Cod sursa (job #255172)
Cod sursa(job #255172)
program bigbug;
var f,g:text;
a:array[1..250000] of longint;
s,sum:array[0..250000] of int64;
n,m,i,j,x,y,indice:longint;
min,p:int64;
begin
assign(f,'cuburi2.in');
assign(g,'cuburi2.out');
rewrite(g);
reset(f);
readln(f,n,m);
s[0]:=0;
for i:=1 to n do begin
read(f,a[i]);
s[i]:=s[i-1]+a[i];
end;
sum[1]:=a[1];
for i:=2 to n do sum[i]:=sum[i-1]+a[i]*i;
for j:=1 to m do
begin
readln(f,x,y);
min:=900000;
for i:=x to y do
begin
p:=i*(s[i]-s[x-1])-sum[i]+sum[x-1]+sum[y]-sum[i]-i*(s[y]-s[i]);
if p<min then begin
min:=p;
indice:=i
end;
end;
writeln(g,indice,' ',min);
end;
close(f);
close(g);
end.