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 DEBUG false
using namespace std;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N, H, S;
cin >> N >> H >> S;
long long shift = 0, yMin = 0;
multiset <long long> L, R;
L.insert(S);
R.insert(S);
for(int i = 2; i <= N; i++) {
cin >> S;
shift += H;
if(S < *L.rbegin() - shift) {
yMin += (*L.rbegin() - shift) - S;
L.insert(S + shift);
L.insert(S + shift);
R.insert(*L.rbegin() - 2 * shift);
L.erase(L.lower_bound(*L.rbegin()));
}
else if(S > *R.begin() + shift) {
yMin += S - (*R.begin() + shift);
R.insert(S - shift);
R.insert(S - shift);
L.insert(*R.begin() + 2 * shift);
R.erase(R.lower_bound(*R.begin()));
}
else {
L.insert(S + shift);
R.insert(S - shift);
}
}
cout << yMin;
return 0;
}
# | 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... |