Cod sursa(job #2888416)

Utilizator mirceaspPetcu Mircea mirceasp Data 11 aprilie 2022 01:17:53
Problema Branza Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;
ifstream f("branza.in");
ofstream g("branza.out");
int main()
{
    long long n,depozitare,timp,cost,cerere,i,suma;
    f >> n >> depozitare >> timp;
    deque<long long>dv;
    deque<long long >dp;
    i = 0;
    suma = 0;
    while (f>>cost>>cerere) {
        while (!dp.empty() && !dv.empty() && i-timp == dp.back())
        {
            dp.pop_front();
            dv.pop_front();
        }
        while (!dp.empty() && !dv.empty() && cost<= dv.back()+depozitare*(i-dp.back())) {
            dv.pop_back();
            dp.pop_back();
        }
        dv.push_back(cost);
        dp.push_back(i);

        suma += cerere*(dv.front() + depozitare*(i-dp.front()));



        i++;

    }
    g<<suma;
    return 0;
}