This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define pb push_back
#define sz(x) (int)x.size()
#define f first
#define s second
#define vi vector<int>
#define vpii vector<pii>
#define ll long long
using namespace std;
priority_queue<ll,vector<ll>,greater<ll>>lq;
priority_queue<ll>rq;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n;ll h;cin>>n>>h;
ll ans=0;
ll x;cin>>x;
lq.push(x);
rq.push(x);ans=0;
for(ll i=1;i<n;i++){
cin>>x;
ll rl = i*h;
ll rr = i*h;
if(x-rl>lq.top()){
lq.push(x-rl);
ans+=(x-rl)-lq.top();
lq.push(x-rl);
rq.push(lq.top()+2*rl);
lq.pop();
}
else if(x+rr<rq.top()){
rq.push(x+rr);
ans+=rq.top()-(x+rr);
rq.push(x+rr);
lq.push(rq.top()-rl-rr);
rq.pop();
}
else {
lq.push(x-rl);
rq.push(x+rr);
}
}cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |