Pagini recente » Cod sursa (job #1696420) | Cod sursa (job #2752418) | Istoria paginii runda/cnitv_gimnaziu_1 | Cod sursa (job #1358664) | Cod sursa (job #2801712)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("branza.in");
ofstream fout ("branza.out");
const int DIM = 1e5 + 5;
int n, add, k, sol;
int cst[DIM], sale;
deque <int> cheese;
int main (){
fin>>n>>add>>k;
for(int i=1; i<=n; i++){
fin>>cst[i]>>sale;
while(!cheese.empty() && cst[i] < cst[cheese.back()] + add * (i - cheese.back()))
cheese.pop_back();
cheese.push_back(i);
sol += sale * (cst[cheese.front()] + add * (i - cheese.front()));
if(i >= k && cheese.front() == i-k+1)
cheese.pop_front();
}
fout<<sol;
return 0;
}