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;
int main(){
long long n, h;
cin >> n >> h;
long long val1 = 0;
long long val2 = 0;
long long ans = 0;
long long cur = -1e18;
priority_queue<long long> L, R;
for (int i = 1; i <= n; ++i) {
long long x;
cin >> x;
if (x >= cur) {
R.push(-x + val1);
R.push(-x + val1);
L.push(-R.top() + val1 - val2);
R.pop();
ans += x - L.top() - val2;
}
else {
L.push(x - val2);
L.push(x - val2);
R.push(-L.top() - val2 + val1);
L.pop();
ans += -R.top() + val1 - x;
}
val2 -= h;
val1 += h;
cur = L.top() + val2;
}
cout << ans << '\n';
}
# | 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... |