#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; template inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; ll P; cin >> N >> P; vector H(N); for(int i = 0; i < N; ++i) cin >> H[i]; constexpr ll inf = 1e+17; vector> dp(N, vector(2, inf)); dp[0][0] = 0; for(int i = 0; i + 1 < N; ++i){ if(dp[i][0] != inf){ chmin(dp[i + 1][0], dp[i][0] + max(0LL, H[i + 1] - H[i])); chmin(dp[i + 1][1], dp[i][0] + P); } if(dp[i][1] != inf){ chmin(dp[i + 1][0], dp[i][1] + P); chmin(dp[i + 1][1], dp[i][1] + max(0LL, H[i] - H[i + 1])); } } cout << min(dp[N - 1][0], dp[N - 1][1]) << endl; return 0; }