Cod sursa(job #1992812)

Utilizator dragos231456Neghina Dragos dragos231456 Data 21 iunie 2017 15:17:03
Problema Branza Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;
ifstream f("branza.in");
ofstream g("branza.out");
int n,t,s,cost[100005],cant;
long long rez;
deque<int> deq;
int main()
{
    f>>n>>s>>t;
    for(int i=1;i<=n;++i)
    {
        f>>cost[i]>>cant;
        if(!deq.empty() && i-deq.front()>=t)
        {
            deq.pop_front();
        }
        while(!deq.empty() && cost[i]<=cost[deq.back()]+s*(i-deq.back()))
        {
            deq.pop_back();
        }
        deq.push_back(i);
        rez+=(cost[deq.front()]+s*(i-deq.front()))*cant;

    }
    g<<rez;
    return 0;
}