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>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
ll rs = 0,ls = 0,ans = 0;
multiset<ll> lst,rst;
ll N,H;
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N>>H;
int k;
cin>>k;
lst.insert(k);
rst.insert(k);
ls = -H,rs = H;
for(int i = 2;i<=N;i++){
ll k;
cin>>k;
ll lx = *lst.rbegin()+ls,rx = *rst.begin()+rs;
if(lx>=k){
ans += lx-k;
rst.insert(lx-rs);
lst.erase(lst.find(*lst.rbegin()));
lst.insert(k-ls);
lst.insert(k-ls);
}
else if(rx>=k){
lst.insert(k-ls);
rst.insert(k-rs);
}
else{
ans += k-rx;
lst.insert(rx-ls);
rst.erase(rst.find(*rst.begin()));
rst.insert(k-rs);
rst.insert(k-rs);
}
ls -= H,rs += H;
}
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... |