Cod sursa(job #2053375)

Utilizator FrincuFrinculeasa Alexandru Frincu Data 31 octombrie 2017 18:24:14
Problema Branza Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <iostream>
#include <fstream>
using namespace std;

long long c[100000],p[100000],sum=0;
int n,s,t,i,st=0,dr=-1,d[100000];
int main()
{
    ifstream f("branza.in");
    ofstream g("branza.out");
    f>>n>>s>>t;
    t++;
    for(i=0; i<n; i++)
        f>>c[i]>>p[i];
   for(i=0;i<n;i++)
   {
       if(st<=dr && d[st]==i-t)
        st++;
       while(st<=dr && c[i]<=c[d[dr]]+s*(i-d[dr]))
        dr--;
       d[++dr]=i;
       sum=sum+p[i]*(long long)(c[d[st]]+s*(i-d[st]))
   }
   g<<sum;
    return 0;
}