Cod sursa(job #1525540)

Utilizator superstar1998Moldoveanu Vlad superstar1998 Data 15 noiembrie 2015 11:02:06
Problema Branza Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <iostream>
#include <fstream>
#include <deque>
#define MAX_N 100001
using namespace std;
deque<long long> d;
long long C[MAX_N],P[MAX_N],n,t;
long long total,s;
void citeste()
{
    ifstream f("branza.in");
    f>>n>>s>>t;
    for(int i=1;i<=n;i++)
        f>>C[i]>>P[i];
    f.close();
}
int main()
{
    citeste();
    d.push_back(1);
    total=C[1]*P[1];
    cout<<total<<" ";
    for(int i=2;i<=n;i++)
    {
        while(!d.empty()&&C[i]<C[d.back()]+(i-d.back())*s)d.pop_back();
        d.push_back(i);
        while(i-d.front()>=t)d.pop_front();
        cout<<(C[d.front()]+(i-d.front())*s)<<" ";
        total+=(C[d.front()]+(i-d.front())*s)*P[i];
    }
    ofstream g("branza.out");
    g<<total;
    g.close();
    return 0;
}