#include <bits/stdc++.h>
using namespace std;
const int N = 100010, M = 1000010, P = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int INF = 0xcfcfcfcf;
const double eps = 1e-6, pi = asin(1) * 2;
inline long long read();
inline int ADD(int a, int b) { return a + b >= P ? a + b - P : a + b; }
inline int MINUS(int a, int b) { return a - b < 0 ? a - b + P : a - b; }
int n, k;
struct aa {
  int a, b, c;
} a[N];
inline bool operator<(const aa &a, const aa &b) { return a.c > b.c; }
int dp[N];
inline long long read() {
  long long s = 0;
  bool flag = false;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') flag = true;
  for (; '0' <= ch && ch <= '9'; ch = getchar())
    s = (s << 3) + (s << 1) + (ch ^ '0');
  if (flag) return -s;
  return s;
}
int main() {
  n = read(), k = read();
  for (int i = 1; i <= n; i++) a[i].a = read();
  for (int i = 1; i <= n; i++) a[i].b = read(), a[i].c = a[i].a - k * a[i].b;
  sort(a + 1, a + n + 1);
  memset(dp, 0xcf, sizeof(dp));
  dp[0] = 0;
  int s = 0;
  for (int i = 1; i <= n; i++) {
    assert(i == n || a[i].c >= a[i + 1].c);
    s += max(a[i].c, 0);
    if (a[i].c > 0)
      for (int j = s; j >= a[i].c; j--)
        dp[j] = max(dp[j], dp[j - a[i].c] + a[i].a);
    else
      for (int j = 0; j <= s; j++) dp[j] = max(dp[j], dp[j - a[i].c] + a[i].a);
  }
  if (!dp[0])
    printf("-1\n");
  else
    printf("%d\n", dp[0]);
  return 0;
}
