Pagini recente » Cod sursa (job #404547) | Cod sursa (job #1223075) | Cod sursa (job #2494776) | Cod sursa (job #2134353) | Cod sursa (job #3140244)
#include <fstream>
#include <deque>
#include <vector>
using namespace std;
ifstream in("branza.in");
ofstream out("branza.out");
deque<pair<int,int>> 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 + (i-bestprices.front().second)*s*quantity;
// v.emplace_back(c,p);
// long long bestprice = c;
// for(int index=i-1; index>=max(0, i-t); index--){
// bestprice = min(bestprice, v[index].first + (i-index)*s);
// }
// ans+=bestprice*p;
}
out<<ans;
}