Cod sursa(job #2801712)

Utilizator BlueLuca888Girbovan Robert Luca BlueLuca888 Data 16 noiembrie 2021 19:50:06
Problema Branza Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <bits/stdc++.h>

using namespace std;

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

const int DIM = 1e5 + 5;
int n, add, k, sol;
int cst[DIM], sale;
deque <int> cheese;

int main (){
    fin>>n>>add>>k;
    for(int i=1; i<=n; i++){
        fin>>cst[i]>>sale;

        while(!cheese.empty() && cst[i] < cst[cheese.back()] + add * (i - cheese.back()))
            cheese.pop_back();
        cheese.push_back(i);

        sol += sale * (cst[cheese.front()] + add * (i - cheese.front()));
        if(i >= k && cheese.front() == i-k+1)
            cheese.pop_front();
    }
    fout<<sol;
    return 0;
}