Pagini recente » Istoria paginii runda/pregatire_oji_11-12_4/clasament | Cod sursa (job #1734040) | Cod sursa (job #2298052) | Autentificare | Cod sursa (job #2681844)
#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.empty()&&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;
}