Cod sursa(job #3188738)

Utilizator MrPuzzleDespa Fabian Stefan MrPuzzle Data 3 ianuarie 2024 19:29:59
Problema Branza Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <bits/stdc++.h>

#define DIM 100000

//#define int long long

using namespace std;

//ifstream f("in.in");
//ofstream g("out.out");

ifstream f("branza.in");
ofstream g("branza.out");

int n,s,t;
int v[DIM+5];
int x,sol = 0;

deque <int> q;

signed main(){

    f>>n>>s>>t;
    for(int i=1;i<=n;i++){
        f>>v[i]>>x;

        while(!q.empty() && q.front() < i-t){
            q.pop_front();
        }

        while(!q.empty() &&  (i-q.back())*s + v[q.back()] >= v[i]){
            q.pop_back();
        }

        q.push_back(i);

        sol +=  x * ( (i-q.front())*s + v[q.front()] );
    }

    g<<sol;

    return 0;
}