# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
834468 | urieg | Safety (NOI18_safety) | C++17 | 45 ms | 5404 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>
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define ve vector
typedef long long ll;
using namespace std;
int main(){
// ios_base::sync_with_stdio(0);cin.tie(0);
ll n, a, h;
priority_queue<ll>ql;
priority_queue<ll, vector<ll>, greater<ll>>qr;
long long ans = 0, h1=0,h2=0;
scanf("%lld%lld%lld", &n, &h, &a);
ql.push(a);
qr.push(a);
for(int i = 1; i<n; i++){
h1 -= h;
h2 += h;
scanf("%lld", &a);
if(ql.top()+h1<a && a<qr.top()+h2){
ql.push(a-h1);
qr.push(a-h2);
}
else if(a <= ql.top()+h1){
ans += ql.top()+h1 - a;
ql.push(a-h1);
ql.push(a-h1);
qr.push(ql.top()+h1-h2);
ql.pop();
}
else if(qr.top()+h2 <= a){
ans += a - qr.top()-h2;
qr.push(a-h2);
qr.push(a-h2);
ql.push(qr.top()+h2-h1);
qr.pop();
}
}
cout<<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... |