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>
#pragma GCC optimize("O3","unroll-loops")
#pragma GCC target ("avx2")
using namespace std;
priority_queue<long long>pql;
priority_queue<long long,vector<long long>,greater<long long> >pqr;
long long lzl,lzr;
int ans=0;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,h;
cin>>n>>h;
for(int i=0;i<n;i++){
int a;
cin>>a;
if(i>0&&a<pql.top()+lzl){
//cout<<"left\n";
pql.push(a-lzl);
pql.push(a-lzl);
ans+=abs(a-pql.top()-lzl);
pqr.push(pql.top()+lzl-lzr);
pql.pop();
}else if(i>0&&a>pqr.top()+lzr){
//cout<<"right\n";
pqr.push(a-lzr);
pqr.push(a-lzr);
ans+=abs(a-pqr.top()-lzr);
pql.push(pqr.top()+lzr-lzl);
pqr.pop();
}else{
//cout<<"middle\n";
pql.push(a-lzl);
pqr.push(a-lzr);
}
lzl-=h;
lzr+=h;
//cout<<ans<<" ";
}
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... |