#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define EPS 1e-8
#define sz(s) int(s.size())
#define rall(s) s.rbegin(), s.rend()
#define TC int t; cin >> t; while(t--)
#define getline(s) getline(cin >> ws, s)
#define all(vec) vec.begin(), vec.end()
#define updmin(a, b) a = min((ll)a, (ll)b)
#define updmax(a, b) a = max((ll)a, (ll)b)
#define Num_of_Digits(n) ((int)log10(n) + 1)
#define endd(s) return void(cout << s << "\n")
#define fixed(n) cout << fixed << setprecision(n)
#define ceill(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
#define cin_2d(vec, n, m) for(int i=0;i<n;i++) for(int j=0;j<m&&cin>>vec[i][j];j++);
#define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" << "\n";
#define ordered_set tree<ll, null_type, less <ll>, rb_tree_tag,tree_order_statistics_node_update>
#define multi_ordered_set tree<ll, null_type, less_equal <ll>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
typedef long double ld;
const ll N = 2 * 1e5 + 5;
const ll mod = 1000000007;
const ll INF = 1LL << 60;
void Gerges_Hany(){
ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
#endif
}
template < typename T = int > istream& operator >> (istream &in, vector < T > &v) {
for (auto &x : v) in >> x; return in;
}
template < typename T = int > ostream& operator << (ostream &out, const vector < T > &v) {
for (const T &x : v) out << x << ' '; return out;
}
/*
* don't be lazy in thinking
* Think twice, code once
* Think of different approaches to tackle a problem: write them down
* Think of different views of the problem. don't look from only one side
*/
ll n, x;
vector < ll > a, b;
ll dp[101][200005];
ll get_min(ll Idx, ll sum){
if(Idx == n)
return !sum ? 0 : -INF;
ll &ret = dp[Idx][sum + 10000]; // sum + 10000 to make it positive
if(~ret) return ret;
ret = -INF;
ret = max(ret, get_min(Idx + 1, sum));
ret = max(ret, a[Idx] + get_min(Idx + 1, sum + (a[Idx] - (b[Idx] * x))));
return ret;
}
void Accepted(){
cin >> n >> x;
a = b = vector < ll > (n);
cin >> a >> b;
memset(dp, -1, sizeof dp);
ll ans = get_min(0, 0);
cout << (0 >= ans ? -1 : ans);
}
int main()
{
Gerges_Hany();
int testcaces = 1, T = 1;
// cin >> testcaces;
while (testcaces--){
// cout << "Case #" << T++ << ": ";
Accepted();
}
Time;
return 0;
}
Health of a person | Divisibility |
A. Movement | Numbers in a matrix |
Sequences | Split houses |
Divisible | Three primes |
Coprimes | Cost of balloons |
One String No Trouble | Help Jarvis! |
Lift queries | Goki and his breakup |
Ali and Helping innocent people | Book of Potion making |
Duration | Birthday Party |
e-maze-in | Bricks Game |
Char Sum | Two Strings |
Anagrams | Prime Number |
Lexical Sorting Reloaded | 1514A - Perfectly Imperfect Array |
580A- Kefa and First Steps | 1472B- Fair Division |
996A - Hit the Lottery | MSNSADM1 Football |