#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define nn '\n'
#define pb push_back
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 0; i < m; ++i) cin >> b[i];
multiset<int> st(all(b));
int ok = 0;
for (int k = 0; k < n; ++k) {
int cnt = a[k];
vector<int> v(all(st));
int sz = v.size();
vector<bool> dp(cnt + 1, false);
dp[0] = true;
for (int i = 0; i < sz; ++i) {
for (int j = cnt; j >= v[i]; --j) {
if (dp[j - v[i]]) {
dp[j] = true;
}
}
}
if (!dp[cnt]) {
ok = 1;
break;
}
int j = cnt;
for (int i = sz - 1; i >= 0 && j > 0; --i) {
if (j >= v[i] && dp[j - v[i]]) {
st.erase(st.find(v[i]));
j -= v[i];
}
}
}
cout << (ok ? "NO" : "YES") << nn;
}
# | 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... |