#include <bits/stdc++.h>
using namespace std;
#define print(a) for(auto x : a){cout << x << " ";}
#define scan(a) for(auto & x : a) {cin >> x;}
#define rall(a) a.rbegin(), a.rend()
#define all(a) a.begin(), a.end()
#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
const ll MOD = 1e9 + 7, INF = 1e18, LOG = 20, N = 1e5 + 5;
inline void solve() {
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
scan(a);
scan(b);
sort(rall(a));
multiset<int> st(b.begin(), b.end());
for (auto s : a) {
int S = s;
vector<int> v(st.begin(), st.end());
int k = v.size();
vector<int> dp(S + 1, -1);
dp[0] = -2;
for (int i = 0; i < k; i++) {
int x = v[i];
for (int sum = S; sum >= x; sum--) {
if (dp[sum] == -1 && dp[sum - x] != -1) {
dp[sum] = i;
}
}
}
if (dp[S] == -1) {
cout << "NO\n";
return;
}
int cur = S;
while (cur > 0) {
int ii = dp[cur];
int x = v[ii];
st.erase(st.find(x));
cur -= x;
}
}
cout << "YES\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
| # | 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... |