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 <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long int ll;
int main() {
int n, h;
cin >> n >> h;
priority_queue<ll> lq;
priority_queue<ll, vector<ll>, greater<ll> > hq;
ll off = 0;
ll val = 0;
for (int i = 0; i < n; i++) {
int e;
cin >> e;
if (i > 0) off += h;
else {
hq.push(e);
lq.push(e);
continue;
}
ll cut = lq.top() - off;
if (e <= cut) {
val += cut - e;
lq.push(e+off);
lq.push(e+off);
hq.push(lq.top() - off - off);
lq.pop();
} else {
if (e > hq.top() + off) val -= hq.top() + off - e;
hq.push(e-off);
hq.push(e-off);
lq.push(hq.top() + off + off);
hq.pop();
}
}
cout << val << "\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... |