Cod sursa(job #254287)

Utilizator jeanFMI - Petcu Ion Cristian jean Data 7 februarie 2009 10:34:06
Problema Cuburi2 Scor 50
Compilator cpp Status done
Runda Stelele Informaticii 2009, clasele 9-10, ziua 2 Marime 0.44 kb
#include<fstream.h>

unsigned int n,m,p,u,v[250010],i;
unsigned long long cost,s,d;

int main()

{

ifstream f("cuburi2.in");
ofstream g("cuburi2.out");

f>>n>>m;

for(i=1;i<=n;i++) f>>v[i];

for(i=1;i<=m;i++)

 { f>>p>>u; cost=0;

   s=v[p]; d=v[u];

   while(p!=u)

     if(s<d) { cost+=s; p++; s+=v[p];}

       else { cost+=d; u--; d+=v[u];}

   g<<p<<" "<<cost<<'\n';

 }

f.close();
g.close();
return 0;
}