Pagini recente » Cod sursa (job #898611) | Cod sursa (job #1942185) | Cod sursa (job #1447303) | Cod sursa (job #2670449) | Cod sursa (job #2888811)
#include <iostream>
#include <deque>
#include <fstream>
using namespace std;
ifstream fin("branza.in");
ofstream fout("branza.out");
int main()
{
long long N, T, S, pret, cantitate;
fin >> N >> S >> T;
deque<pair<long long, long long>>deck;
long long suma = 0;
for (int i = 1; i <= N; ++i)
{
fin >> pret >> cantitate;
while (!deck.empty() && deck.front().second + T < i)
{
deck.pop_front();
}
while (!deck.empty() && deck.back().first + (i - deck.back().second) * S > pret)
deck.pop_back();
deck.push_back(make_pair(pret, i));
suma += (deck.front().first + (i - deck.front().second) * S) * cantitate;
//cout << (deck.front().first + (i - deck.front().second) * S) * cantitate << endl;
}
fout << suma;
}