Mai intai trebuie sa te autentifici.

Cod sursa(job #3136918)

Utilizator Radu_BicliBiclineru Radu Radu_Bicli Data 9 iunie 2023 11:25:10
Problema Branza Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("sum2.in");
ofstream fout("sum2.out");
long long n, t, s, i, c[100002], p[100002], r;
deque<long long> b;

int main() {
    fin >> n >> s >> t;
    for(i = 1; i <= n; i++) fin >> c[i] >> p[i];
    for(i = 1; i <= n; i++) {
        while(!b.empty() && c[i] <= c[b.back()] + s * (i - b.back())) b.pop_back();
        b.push_back(i);
        if(i - b.front() > t) b.pop_front();
        r += p[i] * (s * (i - b.front()) + c[b.front()]);
    }
    fout << r;

    return 0;
}