# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
559801 | krit3379 | Safety (NOI18_safety) | C++17 | 56 ms | 5380 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;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define N 200005
typedef long long ll;
ll x,h,shift,ymin;
priority_queue<ll> l;
priority_queue<ll,vector<ll>,greater<ll>> r;
int main(){
int n;
scanf("%d %lld",&n,&h);
scanf("%lld",&x);
l.push(x),r.push(x);
while(--n){
scanf("%lld",&x);
shift+=h;
if(x<l.top()-shift){
ymin+=l.top()-shift-x;
r.push(l.top()-2*shift);
l.pop();
l.push(x+shift);
l.push(x+shift);
}
else if(x>r.top()+shift){
ymin+=x-r.top()-shift;
l.push(r.top()+2*shift);
r.pop();
r.push(x-shift);
r.push(x-shift);
}
else{
l.push(x+shift);
r.push(x-shift);
}
}
printf("%lld",ymin);
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... |