Cod sursa(job #2889048)

Utilizator biancar28Radulescu Alexia-Bianca biancar28 Data 12 aprilie 2022 09:25:11
Problema Branza Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;

ifstream f("branza.in");
ofstream g("branza.out");
long long n,s,t,i=1,sumamin,c[10000001],p;
int main(){
    deque<long long>branza;
    f>>n>>s>>t;

    while(i<=n){
        f>>c[i]>>p;

        while(!branza.empty() && branza.front()<i-t){
            branza.pop_front();
        }
        while(!branza.empty() && (c[branza.back()] + s*(i-branza.back()))>c[i]){
            branza.pop_back();
        }
        branza.push_back(i);
        sumamin += p*(c[branza.front()] + s*(i-branza.front()));
        i++;

    }
    g<<sumamin;
    f.close();
    g.close();
    return 0;
}