# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
208122 | DystoriaX | Safety (NOI18_safety) | C++14 | 85 ms | 5528 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;
int n, h;
int x;
long long ans;
priority_queue<long long> lf;
priority_queue<long long, vector<long long>, greater<long long> > rg;
int main(){
scanf("%d%d", &n, &h);
//First input
scanf("%d", &x);
lf.push(x), rg.push(x);
for(int i = 1; i < n; i++){
long long lazy = 1LL * h * i;
scanf("%d", &x);
if(x < lf.top() - lazy){
ans += lf.top() - lazy - x;
rg.push(lf.top() - (lazy << 1));
lf.push(x + lazy);
lf.push(x + lazy);
lf.pop();
} else if (rg.top() + lazy < x){
ans += x - (rg.top() + lazy);
lf.push(rg.top() + (lazy << 1));
rg.push(x - lazy);
rg.push(x - lazy);
rg.pop();
} else {
lf.push(x + lazy);
rg.push(x - lazy);
}
}
printf("%lld\n", ans);
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... |