Cod sursa(job #2986304)

Utilizator Dragu_AndiDragu Andrei Dragu_Andi Data 28 februarie 2023 11:19:03
Problema Branza Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <fstream>
#include <deque>

using namespace std;

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

const int nmax=1e5+1;

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