Cod sursa(job #2728042)

Utilizator bestman4111Tiberiu Niculae bestman4111 Data 22 martie 2021 18:59:32
Problema Branza Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;
ifstream cit("branza.in");
ofstream afis("brabnza.out");
int main()
{
    deque <long long> d;
    long long n,s,t;
    long long minim=0;
    cit>>n>>s>>t;
    long long c[n+10], p[n+10];
    for(int i=0; i<n; i++)
    {
        cit>>c[i]>>p[i];
        while((!d.empty())&&(c[i]<=c[d.back()]+(i-d.back())*s))
            d.pop_back();
        while((!d.empty())&&(i-d.front()>t))
            d.pop_front();
        d.push_back(i);
        minim = minim + p[i]*(c[d.front()]+(i-d.front())*s);
    }
    afis<<minim<<endl;
    return 0;
}