Pagini recente » Cod sursa (job #1524524) | Cod sursa (job #657766) | Cod sursa (job #2926700) | Cod sursa (job #2423445) | Cod sursa (job #2729246)
#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;
}