Pagini recente » Cod sursa (job #51509) | Cod sursa (job #950275) | Cod sursa (job #241822) | Cod sursa (job #2706211) | Cod sursa (job #255176)
Cod sursa(job #255176)
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;
sum[0]:=0;
for i:=1 to n do begin
read(f,a[i]);
s[i]:=s[i-1]+a[i];
sum[i]:=sum[i-1]+a[i]*i
end;
for j:=1 to m do
begin
readln(f,x,y);
min:=9223372036854775807;
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.