Cod sursa(job #2765630)
| Utilizator | Data | 28 iulie 2021 19:52:33 | |
|---|---|---|---|
| Problema | Branza | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.65 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("branza.in");
ofstream g("branza.out");
int n,s,t,v[100005];
deque<int> d;
int main()
{
f>>n>>s>>t;
long long rez = 0;
for(int i=1;i<=n;i++)
{
int cnt;
f>>v[i]>>cnt;
long long val = v[i]+1LL*(n-i)*s;
while(!d.empty() && v[i]+1LL*(n-i)*s<v[d.back()]+1LL*(n-d.back())*s)
{
d.pop_back();
}
d.push_back(i);
while(!d.empty() && d.front()<i-t)
{
d.pop_front();
}
rez+=1LL*cnt*(v[d.front()]+1LL*(i-d.front())*s);
}
g<<rez<<'\n';
return 0;
}
