Cod sursa(job #3309247)

Utilizator Mihai09Mihai Arteni Mihai09 Data 2 septembrie 2025 21:10:38
Problema Branza Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <fstream>
#include <deque>
#include <tuple>

using namespace std;

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

deque<pair<int,int>>deq;
int n,x,k,s,ans,t;

int main()
{
    fin >>n >>s >>t;
    for(int i = 1;i <= n;i++)
    {
        fin >>x >>k;
        while(!deq.empty())
        {
            if(x <= deq.back().first + s*(i-deq.back().second))
            {
                deq.pop_back();
            }
            else
            {
                break;
            }
        }
        deq.push_back({x,i});
        if(i - deq.front().second > t)
        {
            deq.pop_front();
        }
        ans += k * (deq.front().first + s * (i - deq.front().second));
    }
    fout <<ans;
    return 0;
}