Cod sursa(job #2681845)
| Utilizator | Data | 7 decembrie 2020 00:53:02 | |
|---|---|---|---|
| Problema | Branza | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.55 kb |
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;
ifstream fin ("branza.in");
ofstream fout ("branza.out");
deque<pair<int, int> >h;
int main()
{
long long 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;
}
