Cod sursa(job #254542)

Utilizator ioalexno1Alexandru Bunget ioalexno1 Data 7 februarie 2009 12:52:05
Problema Cuburi2 Scor 20
Compilator fpc Status done
Runda Stelele Informaticii 2009, clasele 9-10, ziua 2 Marime 0.76 kb
program alex;
var f,g:text;
    t:array[1..250000]of longint;
    i,j,x,y,h,m,n,turn,d:longint;
    s,min:int64;
begin
assign(g,'cuburi2.out');rewrite(g);
assign(f,'cuburi2.in');reset(f);
readln(f,n,m);
for i:=1 to n do
    read(f,t[i]);
readln(f);
for i:=1 to m do
    begin
    readln(f,x,y);
    min:=100000000000000000;
    for j:=x to y do
        begin
        s:=0;
        for h:=x to j-1 do
            s:=s+t[h]*(j-h);
        d:=0;
        for h:=j+1 to y do
            begin
            d:=d+1;
            s:=s+t[h]*d;
            end;
        if s<min then begin
                      turn:=j;
                      min:=s;
                      end;
        end;
    writeln(g,turn,' ',min);
    end;
close(f);
close(g);
end.