Pagini recente » Cod sursa (job #42250) | Cod sursa (job #474232) | Cod sursa (job #1940949) | Cod sursa (job #880025) | Cod sursa (job #3287924)
#include <bits/stdc++.h>
using namespace std;
ifstream in("branza.in");
ofstream out("branza.out");
deque<pair<long long,int>> q;
int n,s,t,i;
long long x,y,sm;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
in>>n>>s>>t;
for(i=1;i<=n;++i)
{
in>>x>>y;
while(!q.empty() && q.back().first+s*(i-q.back().second)>x)
q.pop_back();
while(!q.empty()&& q.front().second<=i-t)
q.pop_front();
q.push_back({x,i});
sm+=y*(q.front().first+s*(i-q.front().second));
}
out<<sm;
}