Pagini recente » Cod sursa (job #1650806) | Cod sursa (job #1684291) | Cod sursa (job #2489394) | Cod sursa (job #1102514) | Cod sursa (job #3186332)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("branza.in");
ofstream fout("branza.out");
int v[100005];
deque < pair <int, int> > dq;
int main()
{
int n,t,s,sum = 0,i,p,c;
fin >> n >> s >> t;
for(i = 1; i <= n; i++){
fin >> p >> c;
while(!dq.empty() && dq.front().second <= i - t) dq.pop_front();
while(!dq.empty() && dq.back().first > p - i * s) dq.pop_back();
dq.push_back({p - i * s, i});
sum += c * (i * s + dq.front().first);
}
fout << sum;
return 0;
}