Pagini recente » Cod sursa (job #1329416) | Cod sursa (job #24103) | Cod sursa (job #2376806) | Cod sursa (job #25136) | Cod sursa (job #255196)
Cod sursa(job #255196)
program bgbg;
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;
readln(f);
for j:=1 to m do
begin
readln(f,x,y);
sum[x]:=0;
for i:=x+1 to y do begin
p:=a[i]*(i-x);
sum[x]:=sum[x]+p;
end;
min:=sum[x];
indice:=x;
for i:=x+1 to y do
begin
sum[i]:=sum[i-1]+s[i-1]-s[x-1]-s[y]+s[i-1];
if sum[i]<=min then begin
min:=sum[i];
indice:=i
end;
end;
writeln(g,indice,' ',min);
end;
close(f);
close(g);
end.