# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
200385 | wilwxk | Safety (NOI18_safety) | C++14 | 89 ms | 5524 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;
int n, x;
priority_queue<ll> l;
priority_queue<ll, vector<ll>, greater<ll> > r;
ll llz, rlz;
ll ans;
int main() {
scanf("%d %d", &n, &x);
for(int i = 1; i <= n; i++) {
ll val; scanf("%lld", &val);
if(i == 1) {
l.push(val);
r.push(val);
continue;
}
llz -= x;
rlz += x;
if(val <= l.top()+llz) {
l.push(val-llz);
l.push(val-llz);
r.push(l.top()+llz-rlz);
l.pop();
ans += abs(r.top()+rlz-val);
}
else {
r.push(val-rlz);
r.push(val-rlz);
l.push(r.top()+rlz-llz);
r.pop();
ans += abs(l.top()+llz-val);
}
// printf("%d >> %d %d >> %d %d >> %lld\n", i, l.top(), r.top(), llz, rlz, ans);
}
printf("%lld\n", ans);
}
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... |