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;
#ifdef LOCAL
constexpr bool local = true;
#else
constexpr bool local = false;
#endif
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define ll long long
#define debug if constexpr (local) std::cout
#define endl '\n'
int main() {
	FASTIO
    ll n, h; cin >> n >> h;
    vector<ll> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    
    ll res = 0;
    priority_queue<ll> l;
    priority_queue<ll, vector<ll>, greater<ll>> r;
    l.push(v[0]); r.push(v[0]);
    
    for (int i = 1; i < n; i++){
    	int lopt = l.top() - i*h, ropt = r.top() + i*h;
    	if (v[i] < lopt){
    		res += lopt - v[i];
    		r.push(lopt-i*h);
    		l.push(v[i]+i*h); l.push(v[i]+i*h); l.pop();
		}
		else if (ropt < v[i]){
			res += v[i] - ropt;
			l.push(ropt+i*h);
			r.push(v[i]-i*h); r.push(v[i]-i*h); r.pop();
		}
		else{
			l.push(v[i]+i*h);
			r.push(v[i]-i*h);
		}
	}
	
	cout << res;
}
| # | 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... |