Cod sursa(job #2887558)

Utilizator andriciucandreeaAndriciuc Andreea andriciucandreea Data 9 aprilie 2022 20:04:24
Problema Branza Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <iostream>
#include <fstream>
#include <deque>

using namespace std;

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


int main()
{
    long long n, s, t, cost[100001] = {}, cantitate, cost_total = 0;
    fin>>n>>s>>t;
    deque <long long> v;
    for(int i = 1; i <= n; i++)
    {
        fin>>cost[i]>>cantitate;
        while(!v.empty() && v.front() < i - t)
                v.pop_front();
        while(!v.empty() && cost[v.back()] + (i - v.back()) * s > cost[i])
            v.pop_back();
        v.push_back(i);
        cost_total = cost_total + (cantitate * (cost[v.front()] + (i - v.front()) * s));
    }
    fout<<cost_total;
    return 0;
}