Pagini recente » Cod sursa (job #2063300) | Cod sursa (job #2527295) | Cod sursa (job #1621810) | Cod sursa (job #2578357) | Cod sursa (job #2888562)
#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() != 1 && branzeturi.front().second < i - T)
branzeturi.pop_front();
while(branzeturi.empty() != 1 && ((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;
}