#include<iostream>
#include<queue>
using namespace std;
long long nums[2000000], opts[2000000], from[2000000];
struct day{
    long long opt, cnt, i;
    bool operator < (day a)const{
        return this->opt>a.opt;
    }
};
int main(){
    long long n, k;
    priority_queue<day>days;
    cin>>n>>k;
    for(long long i=0;i<n;i++){
        cin>>nums[i];
        opts[i]=nums[i]-i*k;
    }
    long long ans=0;
    for(long long i=0;i<n;i++){
        /*long long i1=0;
        for(long long j=0;j<i;j++){
            if(opts[j]<opts[i1]){
                i1=j;
            }
        }*/
        if(days.empty()){
            days.push({opts[i], 0, i});
            continue;
        }
        long long i1=days.top().i;

        if(nums[i]-nums[i1]-(i-i1)*k>0){
            //cout<<i<<" "<<i1<<endl;
            ans+=nums[i]-nums[i1]-(i-i1)*k;
            /*if(from[i1]){
                from[i1]=0;
            }else{
                opts[i1]=1000000000000000;
            }*/
            day obj=days.top();
            days.pop();
            if(obj.cnt>0){
                //cout<<i1<<endl;
                obj.cnt=0;
                days.push(obj);
            }

            days.push({opts[i], 1, i});
        }else{
            days.push({opts[i], 0, i});
        }
    }
    cout<<ans<<endl;
    return 0;
}
