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;
using ll = long long;
ll n, h, x, i;
ll miny = 0, lzl, lzr;
priority_queue<ll> l;
priority_queue<ll, vector<ll>, greater<ll>> r;
int main() {
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> h;
for(i=0;i<n;i++) {
cin >> x;
if(l.empty() || r.empty()) {
l.push(x); r.push(x);
} else {
if(x <= l.top()+lzl) {
miny += l.top() + lzl - x;
l.push(x-lzl); l.push(x-lzl); r.push(l.top()+lzl-lzr); l.pop();
} else if(r.top() + lzr <= x) {
miny += x - (r.top() + lzr);
r.push(x-lzr); r.push(x-lzr); l.push(r.top()+lzr-lzl); r.pop();
} else {
l.push(x-lzl); r.push(x-lzr);
}
}
lzl -= h; lzr += h;
}
cout << miny;
}
# | 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... |