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;
using ll = long long;
int main () {
cin.tie(0)->sync_with_stdio(0);
int n;
ll h;
cin >> n >> h;
ll s[n];
priority_queue<ll> lf;
priority_queue<ll, vector<ll>, greater<ll>> rt;
long long res=0;
for(int i = 0;i<n;i++) {
cin >> s[i];
if(i==0) {
lf.push(s[i]);
rt.push(s[i]);
continue;
}
long long c=i*h;
if(s[i]<=lf.top()-c) {
lf.push(s[i]+c);
lf.push(s[i]+c);
res+=abs(lf.top()-(s[i]+c));
rt.push(lf.top()-2*c);
lf.pop();
}
else if(s[i]>=rt.top()+c) {
rt.push(s[i]-c);
rt.push(s[i]-c);
res+=abs(rt.top()-(s[i]-c));
lf.push(rt.top()+2*c);
rt.pop();
}
else {
lf.push(s[i]+c);
rt.push(s[i]-c);
}
}
cout << res << "\n";
}
# | 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... |