Cod sursa(job #1068743)

Utilizator AlexandruValeanuAlexandru Valeanu AlexandruValeanu Data 28 decembrie 2013 18:21:19
Problema Branza Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <iostream>
#include <fstream>
#include <deque>

using namespace std;

const int Nmax = 100001;

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

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

    f >> N >> S >> T;

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

        V[i] = cost - 1LL * i * S;

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

        deck.push_back( i );

        sol += ( V[ deck.front() ] + 1LL * S * i ) * cant;
    }

    g << sol << "\n";

    return 0;
}