Cod sursa(job #1537775)

Utilizator raulmuresanRaul Muresan raulmuresan Data 27 noiembrie 2015 22:48:12
Problema Branza Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include<fstream>
#include<iostream>
#include<vector>
#include <cstring>
#include <deque>
using namespace std;
ifstream fin("branza.in");
ofstream fout("branza.out");

deque <int> d;



int n,m,k,i,j,p,x,y,a[100005],t,s;
long long int sol;



int main()
{
    fin>>n>>s>>t;
    for(i=1;i<=n;i++)
    {
        fin>>a[i]>>p;

        while(!d.empty() && a[d.back()] + s*(i-d.back())  > a[i]){
            d.pop_back();
        }
        d.push_back(i);
        if(d.front() < i - t)
        {
            d.pop_front();
        }
        sol=sol+ ( a[d.front()] + s * (i-d.front()) )*p;

        //fout<<a[i]<<" "<<p<<"\n";

    }
    fout<<sol<<"\n";
}