Cod sursa(job #2054210)

Utilizator heeiyyoosarateanu armand heeiyyoo Data 1 noiembrie 2017 19:40:59
Problema Branza Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <iostream>
#include<fstream>
using namespace std;
int p[100000],d[100000],c[100000];
int main()
{
    int n,s,t,i,st=0,dr=-1;
    long long rez = 0;

    ifstream f("branza.in");
    ofstream o("branza.out");

    f>>n>>s>>t;
    t++;
    for(i=0; i<n; i++)
    {
        f>>c[i]>>p[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;

        rez += p[i] * (c[d[st]] + (long long)s*(i-d[st]));

    }
    o << rez;
    return 0;
}