Cod sursa(job #1641829)
| Utilizator | Data | 9 martie 2016 11:05:14 | |
|---|---|---|---|
| Problema | Branza | Scor | 40 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.54 kb |
#include <iostream>
#include <fstream>
#define Max 100005
using namespace std;
ifstream f("branza.in");
ofstream g("branza.out");
int v[Max], d[Max],n,s,t;
long long sum;
void rez()
{
f>>n>>s>>t;
int head=1,tail=0,i,p;
for(i=1;i<=n;++i)
{
f>>v[i]>>p;
while(head<=tail&&v[i]<v[d[tail]]+((i-d[tail])*s))tail--;
d[++tail]=i;
while(head<=tail&&i-d[head]>=t)head++;
sum+=(long long)(v[d[head]] +(i-d[head])*s)*p;
}
g<<sum;
}
int main()
{
rez();
return 0;
}
