Cod sursa(job #1980215)
| Utilizator | Data | 12 mai 2017 16:13:39 | |
|---|---|---|---|
| Problema | Branza | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.57 kb |
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;
const int nmax=100005;
deque<int> d;
int c[nmax];
int n,s,t,p,i;
long long tot;
int main()
{
ifstream f("branza.in");
ofstream g("branza.out");
f>>n>>s>>t;
for(i=1;i<=n;i++)
{
f>>c[i]>>p;
c[i]=c[i]-i*s;
if((!d.empty())&i-d.front()>t)
d.pop_front();
while((!d.empty())&&c[i]<c[d.back()])
d.pop_back();
d.push_back(i);
tot+=1LL*(c[d.front()]+i*s)*p;
}
g<<tot;
return 0;
}
