# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
241922 | maximath_1 | Safety (NOI18_safety) | C++11 | 79 ms | 5524 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.
/* D10-2 (100) */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
priority_queue<ll>lf;
priority_queue<ll, vector<ll>, greater<ll> >rg;
ll ans=0ll, h;
int n;
int main(){
scanf("%d%lld", &n, &h);
for(int i=0; i<n; i++){
ll x;
scanf("%lld", &x);
if(i==0){
lf.push(x); rg.push(x);
continue;
}
ll shift=i*1ll*h;
ll lfb=lf.top()-shift, rgb=rg.top()+shift;
if(x<lfb){
lf.push(x+shift); lf.push(x+shift);
lf.pop();
rg.push(lfb-shift);
ans+=lfb-x;
}else if(x>rgb){
rg.push(x-shift); rg.push(x-shift);
rg.pop();
lf.push(rgb+shift);
ans+=x-rgb;
}else{
lf.push(x+shift); rg.push(x-shift);
}
}
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... |