Cod sursa(job #2732462)
Utilizator | Data | 28 martie 2021 23:05:54 | |
---|---|---|---|
Problema | Branza | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.53 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("branza.in");
ofstream g("branza.out");
int c[100001],d[100001];
int main()
{
int n,s,t,st=0,dr=-1,x;
long long q=0;
f>>n>>s>>t;
t++;
for(int i=0;i<n;i++){
f>>c[i]>>x;
if(st<=dr&&d[st]==i-t){
st++;
}
while(st<=dr&&c[i]<=c[d[dr]]+s*(i-d[dr])){
dr--;
}
d[++dr]=i;
q+=(c[d[st]]+(long long)s*(i-d[st]))*x;
}
g<<q;
return 0;
}