Cod sursa(job #1508056)

Utilizator projectanduFMI Stanescu Andrei Alexandru projectandu Data 22 octombrie 2015 11:32:10
Problema Cuburi2 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <iostream>
#include <fstream>
using namespace std;

ifstream d("cuburi2.in");
ofstream o("cuburi2.out");

int main()
{
    int n,m,a[250001],x,y,cmax,p,s;
    d>>n>>m;
    for(int i=1;i<=n;i++)
        d>>a[i];
    for(int i=1;i<=m;i++)
    {
        cmax=-1;
        s=0;
        d>>x>>y;
        for(int j=x;j<=y;j++)
            if(a[j]>cmax)
            {
                p=j;
                cmax=a[j];
            }
        for(int j=x;j<p;j++)
            s+=a[j]*(p-j);
        for(int j=p+1;j<=y;j++)
            s+=a[j]*(j-p);
        o<<p<<' '<<s<<'\n';
    }

    return 0;
}