#include <bits/stdc++.h>   using namespace std;   const int inf = 1 << 30;   const long long maxn = 110;   struct node {     int v, cost;   } a[1500];   int N, K, dp1[100 * 150], dp2[100 * 150];   int solve() {     memset(dp1, -0x3f3f3f3f, sizeof(dp1));     ;     memset(dp2, -0x3f3f3f3f, sizeof(dp2));     ;     dp1[1] = dp2[1] = 0;     for (int i = 1; i <= N; i++) {       if (a[i].cost >= 0) {         for (int j = 100 * 105; j >= a[i].cost; j--)           dp1[j] = max(dp1[j], dp1[j - a[i].cost] + a[i].v);       } else {         a[i].cost = -a[i].cost;         for (int j = 100 * 105; j >= a[i].cost; j--)           dp2[j] = max(dp2[j], dp2[j - a[i].cost] + a[i].v);       }     }     int ans = -1;     for (int i = 0; i <= 100 * 105; i++) {       if (dp1[i] + dp2[i] != 0 && dp1[i] + dp2[i] > ans) ans = dp1[i] + dp2[i];     }     return ans;   }   int main() {     cin >> N >> K;     for (int i = 1; i <= N; i++) cin >> a[i].v;     int b;     for (int i = 1; i <= N; i++) cin >> b, a[i].cost = a[i].v - K * b;     cout << solve() << endl;     return 0;   }   