Cod sursa(job #2500012)

Utilizator ArdeleanOficialAlexandru ArdeleanOficial Data 27 noiembrie 2019 09:38:57
Problema Branza Scor 40
Compilator cpp-64 Status done
Runda guritza Marime 0.56 kb
#include <fstream>

using namespace std;

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

const int N = 1e5 + 7;

int c[N], dq[N];

int main()
{
    long long ans(0);
    int n, s, t, p, st(0), dr(-1);
    fin >> n >> s >> t;
    for (int i = 0; i < n; ++i) {
        fin >> c[i] >> p;
        c[i] -= i * s;
        while (st <= dr && c[dq[dr]] >= c[i])
            --dr;
        if (st <= dr && dq[st] <= i - t)
            ++st;
        dq[++dr] = i;
        ans += 1LL * p * (c[dq[st]] + i * s);
    }
    fout << ans;
    return 0;
}