#include <bits/stdc++.h>
#define int long long 
using namespace std;
int32_t main() {
    int n,h,x,ans=0;
    cin >> n >> h;
    priority_queue<int> lq;
    priority_queue<int,vector<int>,greater<int> > rq;
    for(int i = 0;i<n;i++) {
        cin >> x;
        if(i==0){
            lq.push(x);
            rq.push(x);
            continue;
        }
        int range = i * h;
        if(x + range < lq.top()) {
            lq.push(x+range);
            ans += abs(lq.top() - (x+range));
            lq.push(x+range);
            rq.push(lq.top() - 2 * range);
            lq.pop();
        } else if (x - range > rq.top()) {
            rq.push(x-range);
            ans += abs(rq.top() - (x - range));
            rq.push(x-range);
            lq.push(rq.top() + 2 * range);
            rq.pop();
        } else {
            lq.push(x+range);
            rq.push(x-range);
        }
    }
    cout<<ans;
}
| # | 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... |