Cod sursa(job #254446)

Utilizator chelaru_t_achelaru traian andrei chelaru_t_a Data 7 februarie 2009 12:11:34
Problema Cuburi2 Scor 0
Compilator fpc Status done
Runda Stelele Informaticii 2009, clasele 9-10, ziua 2 Marime 0.72 kb
var n,m,i,a,b:longint;
    v:array [1..250000] of longint;
    f,g:text;

 procedure citire;
  var i:longint;
  begin
   readln(f,n,m);
   for i:=1 to n do read(f,v[i]);
   readln(f);
  end;

 procedure cuburi(a,b:longint);
  var i,p,max,t:longint;
  begin
   max:=v[a];
   p:=a;
   for i:=a+1 to b do
     if max<v[i] then
       begin
       max:=v[i];
       p:=i;
       end;
   t:=0;
   for i:=p-1 downto a do t:=t+(p-i)*v[i];
   for i:=p+1 to b do t:=t+(i-p)*v[i];
   writeln(g,p,' ',t);
  end;

begin
  assign(f,'cuburi2.in');
  assign(g,'cuburi2.out');
  reset(f);
  rewrite(g);
  citire;
  for i:=1 to m do
    begin
    readln(f,a,b);
    cuburi(a,b);
    end;
  close(f);
  close(g);
end.