#include using namespace std; struct uns_t {} uns; template auto vec(Element init, Head arg, Args ...args) { if constexpr (sizeof...(Args) == 0) return std::vector(arg, init); else return std::vector(arg, vec(init, args...)); } template auto vec(uns_t, Head arg, Args ...args) { return vec(Element(), arg, args...); } int main() { constexpr int inf = INT_MAX / 4; int n, x; cin >> n >> x; auto a = vec(uns, n); auto b = vec(uns, n); for (auto &e : a) cin >> e; for (auto &e : b) cin >> e; for (auto &e : a) { e -= x; e *= -1; } if (0 < *min_element(begin(a), end(a))) { cout << -1 << endl; return 0; } int all = accumulate(begin(a), end(a), 0); if (all <= 0) { cout << 0 << endl; return 0; } auto dp = vec(inf, n + 1, all + 1); dp[0][0] = 0; for (int i = 1; i <= n; ++i) { for (int j = 0; j <= all; ++j) { if (a[i - 1] <= 0) { dp[i][j] = dp[i - 1][j]; } else { dp[i][j] = min(dp[i - 1][j], dp[i - 1][max(0, j - a[i - 1])] + b[i - 1]); } } } cout << dp[n][all] << endl; }