#include <bits/stdc++.h>
int main() {
  int n, k;
  std::cin >> n >> k;
  std::vector<int> a(n), b(n);
  int sp = 0, sn = 0;
  for (int i = 0; i < n; ++i) {
    std::cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    std::cin >> b[i];
    b[i] *= k;
    int d = a[i] - b[i];
    d > 0 ? sp += d : sn += -d;
    std::cerr << i << ":  " << a[i] << " - " << b[i] << " = " << d << std::endl;
  }
  int z = 0;
  std::vector<int> x(sp + 1, -1), y(sn + 1, -1);
  x[0] = y[0] = 0;
  for (int i = 0; i < n; ++i) {
    int d = a[i] - b[i];
    if (d > 0) {
      for (int w = sp; w >= d; --w) {
        if (x[w - d] >= 0) x[w] = std::max(x[w], a[i] + x[w - d]);
      }
    } else if (d < 0) {
      d = -d;
      for (int w = sn; w >= d; --w) {
        if (y[w - d] >= 0) y[w] = std::max(y[w], a[i] + y[w - d]);
      }
    } else {
      z += a[i];
    }
  }
  int ans = z;
  for (int w = 0; w <= std::min(sp, sn); ++w) {
    if (x[w] != -1 && y[w] != -1) {
      ans = std::max(ans, x[w] + y[w] + z);
    }
  }
  (ans == 0) ? ans = -1 : 0;
  std::cout << ans << std::endl;
}
