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 int long long
using namespace std;
int n,h,s,x,y,res;
priority_queue <int> p,q;
int32_t main(){
ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
cin >> n >> h;
for (int i=0;i<n;i++){
cin >> s;
x=i*h-s,y=s+i*h;
if (p.empty()||x<p.top()){
p.push(x);
p.push(x);
res+=p.top()-x;
q.push(i*h*2-p.top());
p.pop();
}
else if (q.empty()||y<q.top()){
q.push(y);
q.push(y);
res+=q.top()-y;
p.push(i*h*2-q.top());
q.pop();
}
else{
p.push(x);
q.push(y);
}
}
cout << res;
}
# | 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... |