cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= n; ++i) cin >> b[i]; for (int i = n; i; --i) suf[i] = suf[i + 1] + b[i]; ll ans = 0; for (int i = 1, s = 0; i <= n; ++i) { if (suf[i] > 0) s += k, ans += k * suf[i], Q.push({ 2 * k, suf[i] }); else s -= k, ans -= k * suf[i]; while (s > a[i]) { node t = Q.top(); Q.pop(); int p = min(s - a[i], t.k); ans -= p * t.v; s -= p; if (t.k > p) Q.push({ t.k - p, t.v }); } } cout << ans << "\n"; return0; }