#include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; #define INF 9222222222222222222LL ll dp[200005][2]; int main(){ int N; ll P; vector H; cin >> N >> P; rep(i,N){ ll a; cin >> a; H.push_back(a); } rep(i,200005){ dp[i][0] = INF; dp[i][1] = INF; } dp[0][0] = 0; REP(i,1,N){ //i-1 i // -> & -> dp[i][0] = min(dp[i][0], dp[i-1][0] + max(0LL,H[i]-H[i-1])); dp[i][0] = min(dp[i][0], dp[i-1][0] + P); // -> & <- dp[i][1] = min(dp[i][1], dp[i-1][0] + P); // <- & -> dp[i][0] = min(dp[i][0], dp[i-1][1] + P); // <- & <- dp[i][1] = min(dp[i][1], dp[i-1][1] + max(0LL,H[i-1]-H[i])); dp[i][1] = min(dp[i][1], dp[i-1][1] + P); } cout << min(dp[N-1][0], dp[N-1][1]) << endl; return 0; }