Cod sursa(job #2055609)
| Utilizator | Data | 3 noiembrie 2017 15:23:00 | |
|---|---|---|---|
| Problema | Branza | Scor | 100 |
| Compilator | c | Status | done |
| Runda | Arhiva de probleme | Marime | 0.58 kb |
#include <stdio.h>
#define N 100000
int kg[N],c[N],d[N];
int main()
{
FILE *f1 = fopen("branza.in","r"),*f2 = fopen("branza.out","w");
int n,s,t,dr,st,i;
long long sum;
fscanf(f1,"%d%d%d",&n,&s,&t);
t++;
sum = 0;
st = 0;
dr = -1;
for(i=0;i<n;i++){
fscanf(f1,"%d%d",&c[i],&kg[i]);
while(st<=dr && d[st] == i-t)
st++;
while(st<=dr && c[i] <= c[d[dr]] + s*(i-d[dr])){
dr--;
}
d[++dr] = i;
sum +=(long long) (c[d[st]] + s*(i-d[st]))* kg[i];
}
fprintf(f2,"%lld",sum);
return 0;
}
