| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1291138 | kutomei3 | 은행 (IZhO14_bank) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve()
{
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for (int i = 0; i < n; i++) cin >> a[i];
for (int j = 0; j < m; j++) cin >> b[j];
sort(b.rbegin(), b.rned());
vector<int> au(m, true);
for (int p = 0; p < n; p++) {
vector<int> dp(1001, 0), lu(1001, -1);
dp[0] = 1;
for (int i = 0; i < m; i++) {
if (!au[i]) continue;
for (int j = 1000; j >= b[i]; j--) {
if (dp[j - b[i]]) {
dp[j] = 1;
lu[j] = i;
}
}
}
if (!dp[a[p]]) {
cout << "NO";
return;
} else {
int now = a[p];
while (now > 0) {
int id = lu[now];
au[id] = false;
now -= b[id];
}
}
}
cout << "YES";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
return 0;
}
/*
*/
