Cod sursa(job #2639040)
| Utilizator | Data | 30 iulie 2020 21:48:54 | |
|---|---|---|---|
| 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 f("branza.in");
ofstream g("branza.out");
long long n,s,t,i,sum,cost[100005],cant[100005];
deque <long long > d;
int main()
{
f>>n>>s>>t;
for (i=1;i<=n;i++)
{
f>>cost[i]>>cant[i];
while (!d.empty()&&cost[d.back()]+s*(i-d.back())>cost[i])
{
d.pop_back();
}
d.push_back(i);
if (!d.empty()&&d.front()+t<i)
{
d.pop_front();
}
sum=sum+((i-d.front())*s+cost[d.front()])*cant[i];
}
g<<sum;
return 0;
}
