#include #include using namespace std; using namespace atcoder; using ll=int; using ld=long double; ld pie=3.141592653589793; ll inf=1444999994; ll mod=1000000007; int main(){ ll n,x; cin >> n >> x; vectora(n),b(n); ll sum=0; for (ll i = 0; i < n; i++) { cin >> a[i]; a[i]-=x; } for (ll i = 0; i < n; i++) { cin >> b[i]; } vectorc,d; for (ll i = 0; i < n; i++) { if (a[i]<0) { c.push_back(-a[i]); d.push_back(b[i]); }else{ sum+=a[i]; } } n=c.size(); if (n==0) { cout << 0 << endl; return 0; } if (n==a.size()) { cout << -1 << endl; return 0; } vector>dp(n,vector(sum+1,inf)); dp[0][0]=d[0]; if (c[0]<=sum) { dp[0][c[0]]=0; } for (ll i = 1; i < n; i++) { for (ll j = 0; j <=sum; j++) { if (dp[i-1][j]==inf) { continue; } dp[i][j]=min(dp[i][j],dp[i-1][j]+d[i]); if (j+c[i]<=sum) { dp[i][j+c[i]]=min(dp[i][j+c[i]],dp[i-1][j]); } } } ll ans=inf; for (ll i = 0; i <=sum; i++) { ans=min(ans,dp[n-1][i]); } if (ans==inf) { cout << -1 << endl; }else{ cout << ans << endl; } }