#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     int tas[101], cal[101];     int dp1[10001], dp2[10001];     int w1[101][3], w2[101][3];     while ((cin >> n >> k)) {       int s = 0, t = 0;       int sum1 = 0, sum2 = 0, sum = 0;       for (int i = 1; i <= n; ++i) cin >> tas[i];       for (int j = 1; j <= n; ++j) cin >> cal[j];       for (int i = 1; i <= n; ++i) {         int data;         data = tas[i] - k * cal[i];         if (data > 0) {           w1[++s][1] = data;           w1[s][2] = tas[i];           sum1 += data;         } else if (data < 0) {           data = -data;           w2[++t][1] = data;           w2[t][2] = tas[i];           sum2 += data;         } else           sum += tas[i];       }       int max = sum1 <= sum2 ? sum1 : sum2;       int temp = 0;       for (int i = 1; i <= max; ++i) {         memset(dp1, -10000000, sizeof(dp1));         memset(dp2, -10000000, sizeof(dp2));         dp1[0] = dp2[0] = 0;         for (int j = 1; j <= s; ++j) {           for (int v = i; v >= w1[j][1]; --v) {             if (dp1[v] < dp1[v - w1[j][1]] + w1[j][2])               dp1[v] = dp1[v - w1[j][1]] + w1[j][2];           }         }         for (int j = 1; j <= t; ++j) {           for (int v = i; v >= w2[j][1]; --v) {             if (dp2[v] < dp2[v - w2[j][1]] + w2[j][2])               dp2[v] = dp2[v - w2[j][1]] + w2[j][2];           }         }         if (dp1[i] > 0 && dp2[i] > 0) {           if (dp1[i] + dp2[i] > temp) temp = dp1[i] + dp2[i];         }       }       sum += temp;       if (sum == 0)         cout <<  -1  << endl;       else         cout << sum << endl;     }     return 0;   }   