Pagini recente » Cod sursa (job #429615) | Cod sursa (job #2940585) | Cod sursa (job #338706) | Cod sursa (job #567314) | Cod sursa (job #2888223)
#include <iostream>
#include <fstream>
#include <deque>
#include <utility>
using namespace std;
int main() {
ifstream f("branza.in");
ofstream g("branza.out");
long long n,s,timp,pret,cant;
long long total=0;
deque<pair<long long,long long>> br;
f>>n>>s>>timp;
for(int i=0;i<n;++i){
f>>pret>>cant;
while(!br.empty() && pret<br.back().first+s*(i-br.back().second))
br.pop_back();
br.push_back(make_pair(pret,i));
if(br.front().second<i-timp)
br.pop_front();
total += cant*(br.front().first+s*(i-br.front().second));
}
g<<total;
return 0;
}