///Link: https://h...content-available-to-author-only...u.vn/contest/26lqpt10 - NOAI&NOCHEAT@LqPT26
///Author: NHB_0xCKT
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define NAME ""
using namespace std;
const int MM = 1e6+5;
ll a[MM],n,s;
namespace solve1{
    ll dp[1005][1005];
    void sol(){
        for(int i = 0;i<=n;i++){
            for(int j = 0;j<=n;j++){
                dp[i][j] = LLONG_MIN;
            }
        }
        dp[0][0] = 0;
        for(int i = 1;i<=n;i++){
            for(int j = 0;j<=i;j++){
                if(dp[i-1][j] != LLONG_MIN) dp[i][j] = dp[i-1][j] - s*j;
                if(j>0 && dp[i-1][j-1] != LLONG_MIN) dp[i][j] = max(dp[i][j],dp[i-1][j-1] - s*(j-1) - a[i]);
                if(j<i && dp[i-1][j+1] != LLONG_MIN) dp[i][j] = max(dp[i][j],dp[i-1][j+1] - s*(j+1) + a[i]);
            }
        }
        cout<<dp[n][0];
    }
}
namespace solve2{
    ll ans = 0, cnt = 0;
    void sol(){
        priority_queue<ll,vector<ll>,greater<ll>>pq;
        for(int i = 1;i<=n;i++){
            ll val = a[i] - s*i;
            if(!pq.empty() && pq.top() <val){
                ans += val - pq.top();
                pq.pop();
                pq.push(val);
            }
            pq.push(val);
//            cout<<val<<"\n";
//            cout<<i<<" "<<ans<<"\n";
        }
        cout<<ans<<"\n";
    }
}
int main(){
//    freopen(NAME".inp","r",stdin);
//    freopen(NAME".out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>s;
    for(int i = 1;i<=n;i++) cin>>a[i];
    solve2::sol();
    return 0;
}
