# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
328790 | Nirjhor | Safety (NOI18_safety) | C++17 | 70 ms | 7064 KiB |
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;
typedef long long ll;
const int N = 200010;
ll steady, shift;
int n; ll a[N], h;
priority_queue <ll> L;
priority_queue <ll, vector <ll>, greater <ll>> R;
int main() {
scanf("%d %lld", &n, &h);
for (int i = 1; i <= n; ++i) {
scanf("%lld", a + i);
}
L.emplace(a[1]), R.emplace(a[1]);
for (int i = 2; i <= n; ++i) {
shift += h;
ll lt = L.top() - shift, rt = R.top() + shift;
if (a[i] >= lt and a[i] <= rt) {
L.emplace(a[i] + shift);
R.emplace(a[i] - shift);
} else {
if (a[i] < lt) {
L.emplace(a[i] + shift);
L.emplace(a[i] + shift);
R.emplace(L.top() - shift - shift); L.pop();
steady += lt - a[i];
} else {
R.emplace(a[i] - shift);
R.emplace(a[i] - shift);
L.emplace(R.top() + shift + shift); R.pop();
steady += a[i] - rt;
}
}
}
cout << steady << '\n';
return 0;
}
Compilation message (stderr)
# | 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... |