#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main() {
  int n, c;
  scanf("%d %d", &n, &c);
  std::vector<int> p(n);
  std::vector<int> s(n);
  for (int i = 0; i < n; i++) scanf("%d", &p[i]);
  for (int i = 0; i < n; i++) scanf("%d", &s[i]);
  deque<int> f;
  const int INF = 1e9 + 791;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    while (!f.empty() && f.back() == 0) f.pop_back();
    int cur = p[i] - s[i];
    int l = 0;
    int r = 0;
    int low = INF;
    while (1) {
      int nl1 = -INF;
      int nl2 = -INF;
      if (r > l) nl1 = f[l] - c;
      if (r < f.size()) nl2 = f[r];
      int step = (low - cur) / (r - l + 1);
      int nl3 = low - step;
      int nl = max(nl1, nl2);
      nl = max(nl, nl3);
      nl = max(nl, 0);
      if (nl == low) {
        if (low == 0) {
          for (int j = l; j < r; j++) f[j] = 0;
          break;
        }
        int prev = low;
        if (cur < low) {
          prev = low - 1;
          int dec = low - 1 - cur;
          int left = r - l - dec;
          for (int j = l; j < l + left; j++) {
            f[j] = low;
          }
          for (int j = l + left; j < r; j++) {
            f[j] = low - 1;
          }
        } else {
          for (int j = l; j < r; j++) f[j] = low;
        }
        cur = prev;
        for (int j = r; j < f.size(); j++) {
          swap(prev, f[j]);
        }
        f.push_back(prev);
        break;
      } else {
        cur += (r - l) * (low - nl);
        low = nl;
        while (r < f.size() && f[r] == low) r++;
        while (l < r && f[l] == low + c) {
          f[l] -= c;
          l++;
        }
      }
    }
    ans += s[i];
    if (cur < 0) ans += cur;
  }
  printf("%lld\n", ans);
}
