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;
typedef long long ll;
multiset<ll> let, rit; /// just set (?)
ll ans, h;
int n;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> n >> h;
{
ll x; cin >> x;
ans = 0;
let.insert(x);
rit.insert(x);
}
for (ll i = 1; i < n; i++){
ll x; cin >> x;
ll lf = (*(--let.end())) - i * h;
ll rt = (*(rit.begin())) + i * h;
if (lf <= x && rt >= x){
let.insert(x + i * h);
rit.insert(x - i * h);
} else if (rt < x){
ans += abs(rt - x);
/// smth
rit.erase(rit.find(rt - i * h));
rit.insert(x - i * h);
rit.insert(x - i * h);
let.insert(rt + i * h);
} else {
assert(lf > x);
ans += abs(lf - x);
/// do smth
let.erase(let.find(lf + i * h));
let.insert(x + i * h);
let.insert(x + i * h);
rit.insert(lf - i * h);
}
}
cout << ans;
return 0;
}
# | 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... |