#include <bits/stdc++.h>
#pragma comment(linker, "/stack:64000000")
using namespace std;
const int INF = 1000000000;
const int BASE = 1000000007;
const int MAX = 100007;
const int ADD = 1000000;
const int MOD = 1000000007;
const int CNT = 800;
int p[MAX];
int s[MAX];
vector<int> A;
long long sum[MAX];
int P, S;
int n, c;
bool F(int X) {
  long long R = 0;
  int pos1 = lower_bound(A.begin(), A.end(), X + c) - A.begin();
  R += ((int)A.size() - pos1) * 1LL * c;
  int pos2 = lower_bound(A.begin(), A.end(), X) - A.begin();
  R += (sum[pos1] - sum[pos2]) - 1LL * (pos1 - pos2) * X;
  R += P - X;
  return R <= S;
}
int main() {
  cin >> n >> c;
  for (int i = (0); i < (n); i++) {
    scanf("%d", &p[i]);
  }
  for (int i = (0); i < (n); i++) {
    scanf("%d", &s[i]);
  }
  long long res = 0;
  for (int i = (0); i < (n); i++) {
    for (int j = (0); j < ((int)A.size()); j++) sum[j + 1] = sum[j] + A[j];
    int L = 0;
    int R = INF;
    P = p[i];
    S = s[i];
    while (R - L > 1) {
      int X = (L + R) / 2;
      if (F(X))
        R = X;
      else
        L = X;
    }
    if (F(L)) R = L;
    int add = P - R;
    P -= add;
    S -= add;
    for (int h = (0); h < ((int)A.size()); h++) {
      if (A[h] <= R) continue;
      int add = min(c, A[h] - R);
      S -= add;
      A[h] -= add;
    }
    if (P < R) {
      S += R - P;
      P = R;
    }
    A.push_back(P);
    for (int i = (0); i < ((int)A.size() - 1); i++)
      if (A[i] >= P) {
        for (int j = ((int)A.size() - 1) - 1; j >= (i); --j) A[j + 1] = A[j];
        A[i] = P;
        break;
      }
    for (int i = (0); i < ((int)A.size()); i++) {
      if (R > 0 && A[i] == R && S > 0) {
        A[i]--;
        S--;
      }
    }
    res += s[i] - S;
  }
  cout << res << endl;
  return 0;
}
