# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
559261 | M_W | Safety (NOI18_safety) | C++14 | 56 ms | 5388 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 main(){
long long N, H;
scanf("%lld %lld", &N, &H);
long long ymin = 0, shift = 0;
priority_queue<long long> L;
priority_queue<long long, vector<long long>, greater<long long>> R;
long long x;
scanf("%lld", &x);
L.push(x); R.push(x);
for(long long i = 1; i < N; i++){
scanf("%lld", &x);
shift += H;
long long left = L.top() - shift;
long long right = R.top() + shift;
if(x < left){
ymin += abs(left - x);
R.push(left - shift);
L.pop();
L.push(x + shift);
L.push(x + shift);
}
else if(x > right){
ymin += abs(right - x);
L.push(right + shift);
R.pop();
R.push(x - shift);
R.push(x - shift);
}
else{
L.push(x + shift);
R.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... |