Pagini recente » Cod sursa (job #993903) | Cod sursa (job #2723113) | Cod sursa (job #619000) | Cod sursa (job #1681991) | Cod sursa (job #2888560)
#include <iostream>
#include <deque>
#include <fstream>
using namespace std;
deque <pair<int, int>> branzeturi;
ifstream f("branza.in");
ofstream g("branza.out");
int main() {
int N,S,T, cost, cantitate, costFinal = 0;
//pair <int, int> ziCurenta;
f>>N>>S>>T;
for (int i = 1; i <= N; i++)
{
f>>cost>>cantitate;
while(branzeturi.empty() == false && branzeturi.front().second < i - T)
branzeturi.pop_front();
while(branzeturi.empty() == false && ((i - branzeturi.back().first) * S + branzeturi.back().second) > cost)
branzeturi.pop_back();
branzeturi.push_back({i,cost});
costFinal += cantitate * ((i - branzeturi.front().first) * S + branzeturi.front().second);
}
g<<costFinal;
f.close();
g.close();
return 0;
}