Cod sursa(job #3239562)

Utilizator MrPuzzleDespa Fabian Stefan MrPuzzle Data 6 august 2024 15:24:12
Problema Branza Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.67 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 c[DIM+5],p;

int sol = 0;

deque <int> dq;

signed main()
{

    f>>n>>s>>t;
    for(int i=1;i<=n;i++){
        f>>c[i]>>p;
        while(!dq.empty() && i-dq.front() > t){
            dq.pop_front();
        }

        while(!dq.empty() && (i-dq.back()) * s + c[dq.back()]> c[i]){
            dq.pop_back();
        }
        dq.push_back(i);

        sol += ((i-dq.front())*s + c[dq.front()])*p;

    }

    g<<sol<<'\n';

    return 0;
}