This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
# include <bits/stdc++.h>
# define int long long
# define vi vector<int>
# define pb push_back
# define pii pair<int, int>
# define fi first
# define se second
# define endl '\n'
# define jess ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int n, m, a[21], b[21], memo[21][20005];
int dp(int idx, int sum) {
if(idx>m) {
if(sum==a[1]) return 1;
return 0;
}
if(memo[idx][sum]!=-1) return memo[idx][sum];
int best=dp(idx+1, sum);
best=max(best, dp(idx+1, sum+b[idx]));
return memo[idx][sum]=best;
}
void solve() {
memset(memo, -1, sizeof(memo));
cin >> n >> m;
for(int i=1; i<=n; i++) cin >> a[i];
for(int i=1; i<=m; i++) cin >> b[i];
if(dp(1, 0)>0) cout << "YES" << endl;
else cout << "NO" << endl;
}
signed main() {
jess;
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |