Cod sursa(job #2621714)

Utilizator danielsociuSociu Daniel danielsociu Data 30 mai 2020 17:54:50
Problema Branza Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.1 kb
#include <bits/stdc++.h>
using namespace std;
#define ST          first
#define ND          second
#define PB          push_back
#define MKP         make_pair
#define LWBND		lower_bound
#define UPBND		upper_bound
#define FOR(i,a,b)  for(int i=(a);i<=(b);++i)
#define FORS(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x)      x.begin(),x.end()
#define SZ(x)       ((int)(x).size())
#define MOD         1000000007 //998244353
#define MAXN        10005
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<PII> VPII;
const int INF=0x3f3f3f3f;
 
int n,s,t,ans,x,y;
deque<PII> holder;
 
int main()
{
    freopen("branza.in","r",stdin);
    freopen("branza.out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>s>>t;
    FOR(i,1,n){
        cin>>x>>y;
        while(!holder.empty()&&(i-holder.back().ND)*s+holder.back().ST > x)
            holder.pop_back();
        while(!holder.empty() && (i-holder.front().ND) > t)
            holder.pop_front();
        holder.push_back({x,i});
        ans+= y*s*(i-holder.front().ND) + y*holder.front().ST;
    }
    cout<<ans;
}