Language: C++

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

template <typename Tp> inline void getint(Tp &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

int N, cnt, fa[200005]; ll D, A[200005], L[200005], R[200005], ans;
struct edge {int u, v; ll w;} ed[4000005];

inline operator < (const edge &ed1, const edge &ed2) {return ed1.w < ed2.w;}
int getf(const int &u) {return fa[u] == u ? u : fa[u] = getf(fa[u]);}

inline int findmin(const ll *a, int l, const int &r){
	register int res = l;
	while(++l <= r) if(a[l] < a[res]) res = l;
	return res;
}

void build(const int &l, const int &r){
	if(l == r) return; const int mid = l + r >> 1;
	const int Lmin = findmin(L, l, mid), Rmin = findmin(R, mid + 1, r);
	for(register int i = l; i <= mid; i++) ed[++cnt] = (edge){i, Rmin, L[i] + R[Rmin]};
	for(register int i = mid + 1; i <= r; i++) ed[++cnt] = (edge){Lmin, i, L[Lmin] + R[i]};
	build(l, mid), build(mid + 1, r);
}

int main(){
	getint(N), getint(D);
	for(register int i = 1; i <= N; i++) getint(A[i]), fa[i] = i;
	for(register int i = 1; i <= N; i++) L[i] = A[i] - i * D, R[i] = A[i] + i * D;
	build(1, N), sort(ed + 1, ed + cnt + 1);
	for(register int i = 1, bl = N; i <= cnt && bl > 1; i++){
		const int fu = getf(ed[i].u), fv = getf(ed[i].v);
		if(fu != fv) bl--, fa[fv] = fu, ans += ed[i].w;
	}
	return printf("%lld\n", ans), 0;
}

Compiler output:
a.cc: In function 'void getint(Tp&)':
a.cc:11:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   11 |         register int ch, neg = 0;
      |                      ^~
a.cc:11:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   11 |         register int ch, neg = 0;
      |                          ^~~
a.cc: At global scope:
a.cc:21:8: error: ISO C++ forbids declaration of 'operator<' with no type [-fpermissive]
   21 | inline operator < (const edge &ed1, const edge &ed2) {return ed1.w < ed2.w;}
      |        ^~~~~~~~
a.cc: In function 'int findmin(const ll*, int, const int&)':
a.cc:25:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   25 |         register int res = l;
      |                      ^~~
a.cc: In function 'void build(const int&, const int&)':
a.cc:33:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   33 |         for(register int i = l; i <= mid; i++) ed[++cnt] = (edge){i, Rmin, L[i] + R[Rmin]};
      |                          ^
a.cc:34:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   34 |         for(register int i = mid + 1; i <= r; i++) ed[++cnt] = (edge){Lmin, i, L[Lmin] + R[i]};
      |                          ^
a.cc: In function 'int main()':
a.cc:40:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   40 |         for(register int i = 1; i <= N; i++) getint(A[i]), fa[i] = i;
      |                          ^
a.cc:41:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   41 |         for(register int i = 1; i <= N; i++) L[i] = A[i] - i * D, R[i] = A[i] + i * D;
      |                          ^
a.cc:43:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   43 |         for(register int i = 1, bl = N; i <= cnt && bl > 1; i++){
      |                          ^
a.cc:43:33: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   43 |         for(register int i = 1, bl = N; i <= cnt && bl > 1; i++){
      |                                 ^~
a.cc: In instantiation of 'void getint(Tp&) [with Tp = int]':
a.cc:39:8:   required from here
   39 |         getint(N), getint(D);
      |         ~~~~~~^~~
a.cc:11:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   11 |         register int ch, neg = 0;
      |                      ^~
a.cc:11:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   11 |         register int ch, neg = 0;
      |                          ^~~
a.cc: In instantiation of 'void getint(Tp&) [with Tp = long long int]':
a.cc:39:19:   required from here
   39 |         getint(N), getint(D);
      |                    ~~~~~~^~~
a.cc:11:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   11 |         register int ch, neg = 0;
      |                      ^~
a.cc:11:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   11 |         register int ch, neg = 0;
      |                          ^~~