Cod sursa(job #1368724)

Utilizator pepsiM4A1Ozturk Arif pepsiM4A1 Data 2 martie 2015 19:38:07
Problema Cuburi2 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.21 kb
#include <stdio.h>
#define DIM 10000
char buff[DIM];
int poz=0;
void citeste(int &numar)
{
     numar = 0;
     while (buff[poz] < '0' || buff[poz] > '9')
          if (++poz == DIM)
               fread(buff,1,DIM,stdin),poz=0;
     while ('0'<=buff[poz] && buff[poz]<='9')
     {
          numar = numar*10 + buff[poz] - '0';
          if (++poz == DIM)
               fread(buff,1,DIM,stdin),poz=0;
     }
}
int val[250001];
int n,m;
int main()
{
    freopen ("cuburi2.in","r",stdin);
    freopen ("cuburi2.out","w",stdout);
    citeste(n);
    citeste(m);
    for(int i=1;i<=n;i++) citeste(val[i]);
    int p1,p2;
    int maxim=0;
    long long sum=0;
    for(int i=1;i<=m;i++)
    {
        sum=0;
        maxim=0;
        int ind=0;
        citeste(p1);
        citeste(p2);
        for(int j=p1;j<=p2;j++)
        {
            if(maxim<val[j])
            {
                maxim=val[j];
                ind=j;
            }
        }
        long long sum2=0;
        for(int j=p1;j<ind;j++)
        {
            sum=sum*2+val[j];
        }
        for(int j=p2;j>ind;j--)
        {
            sum2=sum2*2+val[j];
        }
        printf("%d %lld\n",ind,sum+sum2);
    }
}