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;
priority_queue<ll,vector<ll>,less<ll>> lef;
priority_queue<ll,vector<ll>,greater<ll>> rig;
int main() {
cin.tie(0)->sync_with_stdio(0);
int n; ll h, x, res = 0;
cin >> n >> h >> x;
lef.push(x); rig.push(x);
for (int i = 1; i < n; i++) {
ll d = h * i; cin >> x;
ll l = lef.top() - d;
ll r = rig.top() + d;
if (x < l) {
lef.push(x + d); lef.push(x + d);
lef.pop(); rig.push(l - d);
res += l - x;
} else if (x > r) {
rig.push(x - d); rig.push(x - d);
rig.pop(); lef.push(r + d);
res += x - r;
} else {
lef.push(x + d); rig.push(x - d);
}
}
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... |