#include <bits/stdc++.h>
#define fi first
#define se second
#define all(v) v.begin() , v.end()
#define sz(v) int(v.size())
#define unq(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
using namespace std;
typedef long long ll;
typedef pair<int , int> ii;
typedef pair<long long , int> lli;
const int maxN = int(2e6)+7;
int n;
ll s , a[maxN];
void solve(){
cin >> n >> s;
for (int i = 1 ; i <= n ; i++){
cin >> a[i];
a[i] -= 1ll * i * s;
}
priority_queue<ll , vector<ll> , greater<ll>> pq;
ll ans = 0;
for (int i = 1 ; i <= n ; i++){
if (pq.empty() == 0 && pq.top() < a[i]){
ans += 1ll * a[i] - pq.top();
pq.pop();
pq.push(a[i]);
}
pq.push(a[i]);
}
cout << ans << "\n";
}
#define name "A"
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen(name".INP" , "r")){
freopen(name".INP" , "r" , stdin);
freopen(name".OUT" , "w" , stdout);
}
int t = 1; //cin >> t;
while (t--) solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgZmkgZmlyc3QKI2RlZmluZSBzZSBzZWNvbmQKI2RlZmluZSBhbGwodikgdi5iZWdpbigpICwgdi5lbmQoKQojZGVmaW5lIHN6KHYpIGludCh2LnNpemUoKSkKI2RlZmluZSB1bnEodikgc29ydChhbGwodikpOyB2LnJlc2l6ZSh1bmlxdWUoYWxsKHYpKSAtIHYuYmVnaW4oKSk7CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKdHlwZWRlZiBwYWlyPGludCAsIGludD4gaWk7CnR5cGVkZWYgcGFpcjxsb25nIGxvbmcgLCBpbnQ+IGxsaTsKCmNvbnN0IGludCBtYXhOID0gaW50KDJlNikrNzsKCmludCBuOwpsbCBzICwgYVttYXhOXTsKCnZvaWQgc29sdmUoKXsKICAgIGNpbiA+PiBuID4+IHM7CiAgICBmb3IgKGludCBpID0gMSA7IGkgPD0gbi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