Pagini recente » Cod sursa (job #408191) | Cod sursa (job #2596581) | Cod sursa (job #2984763) | Cod sursa (job #1318185) | Cod sursa (job #3140245)
#include <fstream>
#include <deque>
#include <vector>
using namespace std;
ifstream in("branza.in");
ofstream out("branza.out");
deque<pair<long long,long long>> bestprices;
int main()
{
int n,s,t;
long long ans=0;
in>>n>>s>>t;
for(int i=1; i<=n; i++){
long long cost,quantity;
in>>cost>>quantity;
while(!bestprices.empty() && cost < bestprices.back().first + (i-bestprices.back().second)*s)
bestprices.pop_back();
bestprices.emplace_back(cost, i);
while(bestprices.front().second - i > t)
bestprices.pop_front();
ans += bestprices.front().first * quantity + ((long long)i-bestprices.front().second)*s*quantity;
}
out<<ans;
}