Pagini recente » Cod sursa (job #2009011) | Cod sursa (job #2283269) | Cod sursa (job #2228712) | Cod sursa (job #2437981) | Cod sursa (job #2681842)
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;
ifstream fin ("branza.in");
ofstream fout ("branza.out");
deque<pair<int, int> >h;
int main()
{
int n, s, t, rsp=0, c, p, i;
fin>>n>>s>>t;
for(i=1; i<=n; i++)
{
fin>>c>>p;
if(h.front().second<i-t) h.pop_front();
while(!h.empty() && c<=h.back().first + s*(i-h.back().second)) h.pop_back();
h.push_back({c, i});
rsp += p*(h.front().first + s*(i-h.front().second));
}
fout<<rsp;
}