Cod sursa(job #2731950)

Utilizator mirunavrAvram Miruna-Alexandra mirunavr Data 28 martie 2021 16:01:12
Problema Branza Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <iostream>
#include<fstream>
#include<deque>
#include<vector>
#include <bits/stdc++.h>
using namespace std;
ifstream f("branza.in");
ofstream g("branza.out");
int N,S,T,suma=0,nr=0,i,x,y,b,ok=1,a;
//vector<int> C;
//vector<int> P;
int C[10000],P[10000];
deque<pair<int,int> > caut;
int main()
{
    f>>N>>S>>T;
    for(i=1; i<=N; i++)
    {
        f>>x>>y;
        //C.push_back(x);
        //P.push_back(y);

        while(!caut.empty() && ( i-caut.front().second )>T)
            caut.pop_front();

        while(!caut.empty() && x<1LL*caut.back().first+1LL*S*(i-caut.back().second))
            caut.pop_back();
        caut.push_back({x,i});
        suma+=1LL* y*(caut.front().first+1LL* S * ( i - caut.front().second ));
    }
    g<<suma;
}