#include <iostream>

using namespace std;

int main()
{
    int n, s;

    int week[100000];
    bool sold[100000];
    cin >> n >> s;

   for(int i=0; i<n; i++){
    cin >> week[i];
   }

    int lastBestI, lastBestQ;
    int q = n-1;
    int currentValue = 0;
    int currentBest = 0;
    while(currentBest>0){

    currentBest=0;
    for(int i=0; i<n-1; i++){
       for(q=i+1; q<n; q++){
        if(sold[q]!=true && sold[i]!=true && max(week[q]-week[i]-s*(q-i), currentBest)>currentBest){
        currentBest = max(week[q]-week[i]-s*(q-i), currentBest);
        lastBestI = i;
        lastBestQ = q;
        }
        }
       }
         sold[lastBestI] = true;
        sold[lastBestQ] = true;
        currentValue += currentBest;
    }


    cout << currentValue;
    return 0;
}
