Pagini recente » Cod sursa (job #2311954) | Cod sursa (job #1699822) | Cod sursa (job #311001) | Cod sursa (job #952529) | Cod sursa (job #254307)
Cod sursa(job #254307)
var f,g:text;
n,m,i,j,x,y,v1,v2,s:longint;
h:array[1..250000] of longint;
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,h[i]);
for i:=1 to m do
begin
read(f,x,y);
write(g,(x+y) div 2,' ');
s:=0; v1:=(x+y) div 2; v2:=v1;
repeat
if v1>1
then begin dec(v1); s:=s+(h[v1]*((x+y) div 2-v1)); end;
if v2<n
then begin inc(v2); s:=s+(h[v1]*((x+y) div 2-v1)); end;
until (v1=1) and (v2=n);
writeln(g,s);
end;
close(f); close(g);
end.