Pagini recente » Cod sursa (job #1757671) | Borderou de evaluare (job #538045) | Cod sursa (job #656724) | Cod sursa (job #2751830) | Cod sursa (job #3140249)
#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(int 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;
}