Cod sursa(job #2729246)

Utilizator Dantelogus99Gruia Gabriel Dantelogus99 Data 24 martie 2021 15:01:40
Problema Branza Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;

ifstream fin("branza.in");
ofstream fout("branza.out");

deque <pair<int, int>> deq;
int weeks, dailyStoreCost, maxStoreTime, weeklyCost, weeklyDemand;
long long totalCost;

int main()
{
    fin >> weeks >> dailyStoreCost >> maxStoreTime;

    for (int i = 1; i <= weeks; i++)
    {
        fin >> weeklyCost >> weeklyDemand;

        while (!deq.empty() && (i - deq.front().second) > maxStoreTime)
            deq.pop_front();

        while (!deq.empty() && (weeklyCost < (deq.back().first + dailyStoreCost * (i - deq.back().second))))
            deq.pop_back();

        deq.push_back({ weeklyCost, i });

        totalCost += weeklyDemand * (deq.front().first + dailyStoreCost * (i - deq.front().second));
    }

    fout << totalCost;
}