Cod sursa(job #2913876)

Utilizator Gica-gicutaGeorge Gica-gicuta Data 17 iulie 2022 16:07:48
Problema Branza Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <fstream>
#include <cmath>
#include <vector>
#include <list>
using namespace std;
ifstream cin("branza.in");
ofstream cout("branza.out");
vector <long long> v;
list <long long> l;
int main()
{
    long long n,s,t,a,b,sum=0;
    cin>>n>>s>>t;
    for(long long i=0;i<n;i++)
    {
        cin>>a>>b;
        v.push_back(a);
        while(l.empty()==0&&v[l.back()]+i*s-l.back()*s>=v[i])
            l.pop_back();
        l.push_back(i);
        if(i-l.front()+1>t)
            l.pop_front();
        sum+=(v[l.front()]+(i-l.front())*s)*b;
    }
    cout<<sum;
    return 0;
}