Pagini recente » Cod sursa (job #240330) | Cod sursa (job #1223024) | Cod sursa (job #797277) | Cod sursa (job #1175624) | Cod sursa (job #3140253)
#include <fstream>
#include <deque>
#include <vector>
#define ll long long
using namespace std;
ifstream in("branza.in");
ofstream out("branza.out");
deque<pair<ll, ll>> bestprices;
int main()
{
ll n,s,t;
ll ans=0;
in>>n>>s>>t;
for(int i=1; i<=n; i++){
ll 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.empty() && i- bestprices.front().second > t)
bestprices.pop_front();
ans += bestprices.front().first * quantity + (i-bestprices.front().second)*s*quantity;
}
out<<ans;
}