Cod sursa(job #2888433)

Utilizator mirceaspPetcu Mircea mirceasp Data 11 aprilie 2022 02:06:20
Problema Branza Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;
int main()
{
    ifstream f("branza.in");
    ofstream g("branza.out");

    long long n,depozitare,timp,cost,cerere,i,suma;
    f >> n >> depozitare >> timp;
    deque<pair<long long,long long> >d;
    suma = 0;
    i = 0;
    while (f>>cost>>cerere)
    {
        while (!d.empty() && cost <= (d.back().second + depozitare*(i-d.back().first)))
            d.pop_back();
        d.push_back({i,cost});
        while (!d.empty() && i-timp > d.front().first)
            d.pop_front();
        suma += cerere*d.front().second + cerere*depozitare*(i-d.front().first);
        i++;
    }
    g<<suma;
    f.close();g.close();
    return 0;
}