Pagini recente » Cod sursa (job #2976242) | Cod sursa (job #3234834) | Cod sursa (job #625012) | Cod sursa (job #3280515) | Cod sursa (job #2729251)
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;
ifstream fin("branza.in");
ofstream fout("branza.out");
deque <pair<int, int>> deq;
long long weeks, dailyStoreCost, maxStoreTime, weeklyCost, weeklyDemand, 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;
}