Cod sursa(job #1266194)

Utilizator diana97Diana Ghinea diana97 Data 18 noiembrie 2014 14:27:08
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");

const int NMAX = 100000 + 1;

int n, s, t;
long long c[NMAX];
deque <int> D;

void rezolva() {
    long long sol = 0;
    int p;
    for (int i = 1; i <= n; i++) {
        f >> c[i] >> p;
        while (!D.empty() && c[i] <= c[D.back()] + s * (i - D.back())) D.pop_back();
        D.push_back(i);
        if (D.front() < i - t) D.pop_front();
        sol = sol + c[D.front()] * p + (s * p * (i - D.front()));
    }
    g << sol << '\n';
}
int main () {
    f >> n >> s >> t;
    rezolva();
    return 0;
}