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 em emplace
using namespace std;
typedef long long ll;
priority_queue<ll> L, R;
int N; ll H, S, A;
int main() {
cin>>N>>H;
for (int i=1; i<=N; i++) {
cin>>S;
if (i==1) { L.em(S), R.em(-S); continue; }
if (S<L.top()-H*(i-1)) A+=(L.top()-H*(i-1))-S, R.em(-L.top()+2*H*(i-1)), L.em(S+H*(i-1)), L.em(S+H*(i-1)), L.pop();
else if (S>-R.top()+H*(i-1)) A+=S+R.top()-H*(i-1), L.em(-R.top()+2*H*(i-1)), R.em(-S+H*(i-1)), R.em(-S+H*(i-1)), R.pop();
else L.em(S+H*(i-1)), R.em(-S+H*(i-1));
}
cout<<A<<'\n';
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... |