#include using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) begin(v),end(v) template inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using pii = pair; constexpr ll INF = 1ll<<30; constexpr ll longINF = 1ll<<60; constexpr ll MOD = 1000000007; constexpr bool debug = false; //---------------------------------// int main() { int N, X; cin >> N >> X; vector A(N), B(N); REP(i, N) scanf("%d", &A[i]); REP(i, N) scanf("%d", &B[i]); // [i][j] := i 科目までみて {選んだ科目の評価の合計 - X} の和が j の最小コスト int offset = 99 * N; vector dp(offset * 2 + 1, INF), ndp; int sum = 0; REP(i, N) { ndp.assign(offset * 2 + 1, INF); const int cur = A[i] - X; REP(j, dp.size()) { if (dp[j] == INF) continue; const int nex = j + A[i] - X; if (nex >= 0 && nex < ndp.size()) chmin(ndp[nex], dp[j]); chmin(ndp[j], dp[j] + B[i]); } chmin(ndp[offset + A[i] - X], sum); sum += B[i]; swap(dp, ndp); } int ans = INF; FOR(i, offset, dp.size()) chmin(ans, dp[i]); if (ans == INF) puts("-1"); else cout << ans << endl; }