Cod sursa(job #2455214)

Utilizator carburatorMitica Carburator carburator Data 10 septembrie 2019 22:29:49
Problema Branza Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <fstream>
#include <deque>
using namespace std;
ifstream fin("branza.in");
ofstream fout("branza.out");
long long N,S,T,C[100001],P,i;
deque <long long> d;
long long sum;
int main()
{
    fin>>N>>S>>T;
    for(i=1;i<=N;i++){
        fin>>C[i]>>P;
        while(!d.empty() && C[d.back()] - S*(d.back()) > C[i] - S*i)d.pop_back();
        d.push_back(i);
        sum+=(C[d.front()]+S*(i-d.front()))*P;
        while(!d.empty() && (i-d.front())>=T)d.pop_front();
    }
    fout<<sum;
    return 0;
}