Cod sursa(job #2732136)

Utilizator petru.burdusaBurdusa Petru petru.burdusa Data 28 martie 2021 19:18:19
Problema Branza Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <iostream>
#include <fstream>
#include<deque>
using namespace std;
int n,s,t,i,c[100005],p;
long long rez;
deque<int>d;

int main() {
    ifstream in("branza.in");
    ofstream out("branza.out");
    in>>n>>s>>t;
    for(i=1;i<=n;i++)
    {
        in>>c[i]>>p;
        while(!d.empty() && c[i] < c[d.back()] + (i-d.back())*s)
            d.pop_back();
        while(!d.empty() && d.front() < i-t)
            d.pop_front();
        d.push_back(i);
        rez += (long long)((long long)p * (c[d.front()] + (long long)(i-d.front()) * s));
    }
    out<<rez;
}