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>
using namespace std;
const int mxn = 1001;
int m, cnt = 0;
vector<int> b;
vector<vector<int>> dp(mxn, vector<int>(21, 0));
vector<int> mp(mxn);
void recurse(int sum, int i) {
if (dp[sum][i]) return;
mp[sum] = 1;
dp[sum][i] = 1;
if (i == m) return;
if (sum + b[i] < mxn) recurse(sum + b[i], i + 1);
recurse(sum, i + 1);
}
void solve() {
int n;
cin >> n >> m;
vector<int> a(n);
b.resize(m);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
recurse(0, 0);
for (int i = 0; i < n; i++) {
if (!mp[a[i]]) {
cout << "NO";
return;
}
}
cout << "YES";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
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... |