Cod sursa(job #3148131)

Utilizator maryyMaria Ciutea maryy Data 29 august 2023 15:02:27
Problema Branza Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <fstream>
#include <deque>
using namespace std;
ifstream in("branza.in");
ofstream out("branza.out");
int main()
{
    long long n, s, t, c, p;
    long long r=0;
    in>>n>>s>>t;
    deque <pair<int, int>>q;
    for(int i=1; i<=n; i++)
    {
        in>>c>>p;
        while(!q.empty() && c<q.back().first +(i-q.back().second)*s)
            q.pop_back();
        q.push_back({c, i});
        while(!q.empty() && i-q.front().second>t)
            q.pop_front();
        r+=p*(q.front().first+s*(i-q.front().second));
    }
    out<<r;
}