Cod sursa(job #1500526)

Utilizator alexandru822Bosinta Alexandru alexandru822 Data 12 octombrie 2015 08:59:27
Problema Branza Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <fstream>

using namespace std;
int stiva[100000];
int c[100000], p[100000];
int main()
{
    ofstream out("branza.out");
    ifstream in("branza.in");
    int n, s, t;
    unsigned long long int cost = 0;
    int top = 0, bottom = 0;
    in >> n >> s >> t;
    for(int i=0; i < n; i++)
    {
        in >> c[i] >> p[i];
        for(int j=bottom; j<top; j++)
            c[stiva[j]] += s;
        if(top-bottom >= t)
            bottom++;
        while(top>bottom && c[i] < c[stiva[top-1]])
            top--;
        stiva[top++] = i;

        cost += c[stiva[bottom]]*p[i];

    }
    out << cost;
}