#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1.0);
const int MAXN = 10001;
const long long INF = 1000ll * 1000ll * 1000ll * 1000ll;
int p;
long long f[MAXN];
long long s[MAXN];
int m;
int bs(long long x) {
  int lg = 0, rg = m;
  while (lg < rg) {
    int md = (lg + rg) / 2;
    if (f[md] < x)
      rg = md;
    else
      lg = md + 1;
  }
  return lg;
}
int aa[MAXN];
int main() {
  ios_base::sync_with_stdio(0);
  long long tot = 0;
  int n;
  long long c;
  cin >> n >> c;
  for (int i = 0; i < n; i++) cin >> aa[i];
  for (m = 0; m < n; m++) {
    s[0] = 0;
    for (int i = 0; i < m; i++) s[i + 1] = s[i] + f[i];
    long long a = aa[m], b;
    cin >> b;
    long long da = 0;
    for (int j = 0; j < m; j++) da += min(c, f[j]);
    b = min(b, da + a);
    tot += b;
    long long vl = a - b;
    p = m;
    long long lg = 0, rg = INF;
    while (lg < rg) {
      long long md = (lg + rg + 1) / 2;
      int l = bs(md + c), r = bs(md);
      long long gv = c * l + (s[r] - s[l] - md * (long long)(r - l));
      if (gv >= md - vl)
        lg = md;
      else
        rg = md - 1;
    }
    long long gg = 0;
    for (int i = 0; i < m; i++) {
      long long gc = max(0ll, min(c, f[i] - lg));
      gg += gc;
      f[i] -= gc;
    }
    gg -= (lg - vl);
    for (int i = 0; i < m; i++) {
      if (gg && (f[i] == lg)) gg--, f[i]++;
    }
    f[m] = lg;
    while ((p > 0) && (f[p] > f[p - 1])) {
      swap(f[p], f[p - 1]);
      p--;
    }
  }
  cout << tot << endl;
  return 0;
}
