Cod sursa(job #3126606)

Utilizator skphaMincu Adrian skpha Data 6 mai 2023 19:43:59
Problema Branza Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <iostream>
#include <vector>
#include <deque>
#include <fstream>

using namespace std;

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

int main()
{
    int n,s,t,count = 0;
    long long pret = 0;
    f>>n>>s>>t;
    
    vector<pair<int,int>>v(n);
    deque<int> d;
    
    for(int i=0;i<n;i++) f>>v[i].first>>v[i].second;

    for(int i=0;i<n;i++) {
        while(!d.empty() && (s*(i-d.back()) + v[d.back()].first) >= v[i].first) d.pop_back();
        d.push_back(i);

        if(d.front() == i-t) d.pop_front();

        pret += (s*v[d.back()].second*(i-d.front()) + v[d.front()].second*v[d.front()].first);
    }

    g<<pret;
    return 0;
}