Cod sursa(job #2610303)
Utilizator | Iceman bem.andrei | Data | 4 mai 2020 18:34:31 |
---|---|---|---|
Problema | Branza | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.58 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream r("branza.in");
ofstream w("branza.out");
deque<long long>d;
int v[100002];
int main()
{
long long n, s, t, c, rez = 0;
r>>n>>s>>t;
t++;
for (int i= 0; i<n; i++)
{
r>>v[i]>>c;
if (d.size()!=0 && d.front()==i-t)
{
d.pop_front();
}
while (d.size()!=0 && v[d.back()]+(i-d.back())*s>=v[i])
{
d.pop_back();
}
d.push_back(i);
rez+=c*(v[d.front()]+(i-d.front())*s);
}
w<<rez;
return 0;
}