Cod sursa(job #1068712)

Utilizator AlexandruValeanuAlexandru Valeanu AlexandruValeanu Data 28 decembrie 2013 18:03:01
Problema Branza Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <iostream>
#include <fstream>
#include <deque>

using namespace std;

const int Nmax = 100001;

int N;
deque <int> deck;
long long sol, S, T;
long long cost[Nmax], cant[Nmax];

int main()
{
    ifstream f("branza.in");
    ofstream g("branza.out");

    f >> N >> S >> T;

    for ( int i = 1; i <= N; ++i )
    {
        f >> cost[i] >> cant[i];

        while ( deck.size() && cost[ deck.back() ] + S * ( i - deck.back() ) > cost[i] ) deck.pop_back();
        while ( deck.size() && deck.front() <= i - T ) deck.pop_front();

        deck.push_back( i );

        sol += cost[ deck.front() ] * cant[i];
        sol += S * cant[i] * ( i - deck.front() );
    }

    g << sol << "\n";

    return 0;
}