# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
586305 | M_W | Safety (NOI18_safety) | C++17 | 62 ms | 5500 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;
priority_queue<long long> lo;
priority_queue<long long, vector<long long>, greater<long long>> hi;
int main(){
int N; long long H, x, ymin = 0, shift = 0;
scanf("%d %lld %lld", &N, &H, &x);
lo.push(x); hi.push(x);
for(int i = 1; i < N; i++){
scanf("%lld", &x);
shift += H;
long long left = lo.top() - shift, right = hi.top() + shift;
if(x <= left){
hi.push(left - shift);
lo.pop();
lo.push(x + shift);
lo.push(x + shift);
ymin += left - x;
}
else if(x >= right){
lo.push(right + shift);
hi.pop();
hi.push(x - shift);
hi.push(x - shift);
ymin += x - right;
}
else{
lo.push(x + shift);
hi.push(x - shift);
}
}
printf("%lld", ymin);
}
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... |