Cod sursa(job #1068709)

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

using namespace std;

const int Nmax = 100001;

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

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 += 1LL * cant * ( V[ deck.front() ] + 1LL * i * S );
    }

    g << sol << "\n";

    return 0;
}