Cod sursa(job #2253664)

Utilizator EmergencyILCAndrei Tudor Popescu EmergencyILC Data 4 octombrie 2018 11:29:47
Problema Cuburi2 Scor 20
Compilator cpp Status done
Runda shimulare_fara_shim Marime 0.88 kb
#include <fstream>

using namespace std;

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

int main()
{
    int n,m;
    int v[250002];
    in>>n>>m;

    for(int i=1; i<=n; i++)
    {
        in>>v[i];
    }

    for(int i=0; i<m; i++)
    {
        int x,y;
        long long min=9999999999;
        in>>x>>y;
        int x1=x,xf=0,t=y-x+1,xff=0;
        for(int j=0; j<t; j++)
        {
            xf=0;
            xf=x1+j;
            int sum=0;
            x=x1;
            for(x; x<=y; x++)
            {
                int d=0;
                if(xf>x)
                    d=xf-x;
                if(xf<x)
                    d=x-xf;
                sum+=v[x]*d;
            }
            if(min>sum)
            {
                min=sum;
                xff=xf;
            }
        }
        out<<xff<<" "<<min<<"\n";
    }
}