Cod sursa(job #2773515)

Utilizator GhiuzanuEdward Ghiuzan Ghiuzanu Data 7 septembrie 2021 13:24:58
Problema Branza Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;

ifstream fin("branza.in");
ofstream fout("branza.out");

long long n, s, t, c[100001], p[100001], cost;
deque<long long> a;

int main() {
    fin>>n>>s>>t;
    for (int i = 0; i < n; ++i) {
        fin>>c[i]>>p[i];
        while (!a.empty() && c[a.back()] + (i - a.back()) * s >= c[i])
            a.pop_back();
        while (!a.empty() && i - a.front() > t)
            a.pop_front();
        a.push_back(i);
        cost = cost + c[a.front()] * p[i] + p[i] * (i - a.front()) * s;
    }
    fout<<cost;
    return 0;
}