Pagini recente » Teoria jocurilor: numerele Sprague Grundy | Cod sursa (job #2888030)
#include <fstream>
#include <deque>
int main()
{
using namespace std;
ifstream in("branza.in");
ofstream out("branza.out");
deque<pair<long long, long long>> cost_deq;
long long saptamani, stoc_cost, max_stoc;
long long cost, cerere,cost_min = 0;
in >> saptamani >> stoc_cost >> max_stoc;
for(int i=0;i<saptamani;++i)
{
in >> cost >> cerere;
while (!cost_deq.empty() && cost <= cost_deq.back().second + stoc_cost * (i - cost_deq.back().first))
cost_deq.pop_back();
cost_deq.push_back(make_pair(i, cost));
if (cost_deq.front().first < i - max_stoc)
cost_deq.pop_front();
cost_min += cerere * (cost_deq.front().second + stoc_cost * (i - cost_deq.front().first));
}
in.close();
out << cost_min;
out.close();
}