#include <bits/stdc++.h>
using namespace std;
#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define endl "\n"
typedef long long ll;
template<class T, class T2> inline ostream &operator <<(ostream &out, const pair<T, T2> &x) { out << x.first << " " << x.second; return out;}
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;

const int MAX_N = 1e6 + 10;
ll arr[MAX_N];
ll n, k;

signed main() {
#ifndef LOCAL
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#endif

    cin >> n >> k;
    for(ll i = 0; i < n; i ++) {
        cin >> arr[i];
        arr[i] -= i * k;
    }

    priority_queue<ll> pq;
    ll ans = 0;
    for(int i = 0; i < n; i ++) {
        pq.push(-arr[i]);
        pq.push(-arr[i]);
        ans += arr[i] + pq.top();
        pq.pop();
    }

    cout << ans << endl;

    return 0;
}
