#include #include #include using namespace std; namespace IO { const int MAX_SIZE = 1 << 20; char buf[MAX_SIZE], *p1 = buf, *p2 = buf; char gc() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAX_SIZE, stdin), p1 == p2) ? EOF : *p1++; } template void R(T &x) { x = 0; char ch = gc(); while (ch < '0' || ch > '9') ch = gc(); while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = gc(); } } } // namespace IO using IO::R; const long long inf = 0x3f3f3f3f3f3f3f3f; int n, w, h1, h2; long long p, b = inf, f; void solve() { R(n), R(w), R(h1); for (int i = 2; i <= n; ++i) { R(h2); f = min(p, b); p = min(f + w, p + (h1 < h2) * (h2 - h1)); b = min(f + w, b + (h2 < h1) * (h1 - h2)); h1 = h2; } printf("%lld", min(p, b)); } int main() { solve(); return 0; }