Pagini recente » Cod sursa (job #490208) | Cod sursa (job #156034) | Cod sursa (job #491445) | Cod sursa (job #1478148) | Cod sursa (job #3140250)
#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()
{
long long n,s,t;
long long ans=0;
in>>n>>s>>t;
for(long long i=1; i<=n; i++){
long long cost,quantity;
in>>cost>>quantity;
if(!bestprices.empty() && bestprices.front().second - i >= t)
bestprices.pop_front();
while(!bestprices.empty() && cost < bestprices.back().first + (i-bestprices.back().second)*s)
bestprices.pop_back();
bestprices.emplace_back(cost, i);
ans += bestprices.front().first * quantity + ((long long)i-bestprices.front().second)*s*quantity;
}
out<<ans;
}