Cod sursa(job #2832939)

Utilizator MrPuzzleDespa Fabian Stefan MrPuzzle Data 14 ianuarie 2022 15:15:01
Problema Branza Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.67 kb
#include<fstream>
#include<iostream>
#include<climits>
#include<algorithm>
#include<cstring>
#include<cmath>

using namespace std;

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

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

long long n,dq[100001],v[100001],st=1,dr=0,c,p,s,t;
long long sol;

int main()
{
    f>>n>>s>>t;

    for(int i=1;i<=n;i++)
    {
        f>>c>>p;
        v[i]=c;

        while(st<=dr&&v[dq[dr]]+(i-dq[dr])*s>=c)
            dr--;
        dr++;
        dq[dr]=i;

        sol+=((v[dq[st]])+(i-dq[st])*s)*p;

        if(i-dq[st]>t)
            st++;

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