| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1313537 | shirokito | 은행 (IZhO14_bank) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
#define ForUp(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define ForDn(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define all(a) (a).begin(), (a).end()
using ll = long long;
const int N = 20;
const int INF = 1e9;
int n, m, a[N], b[N];
int dp[1 << N];
void solve() {
cin >> n >> m;
ForUp (i, 0, n - 1) {
cin >> a[i];
}
ForUp (i, 0, m - 1) {
cin >> b[i];
}
ForUp (mask, 0, (1 << m) - 1) {
dp[mask] = -INF;
}
dp[0] = 0;
int sum = 0;
ForUp (i, 0, n - 1) {
sum += a[i];
ForUp (mask, 0, (1 << m) - 1) {
if (dp[mask] == -INF) continue;
ForUp (j, 0, m - 1) if (!BIT(mask, j)) {
dp[mask | (1 << j)] = dp[mask] + b[j];
}
}
ForUp (mask, 0, (1 << m) - 1) {
if (dp[mask] != sum) dp[mask] = -INF;
}
}
ForUp (mask, 0, (1 << m) - 1) {
if (dp[mask] != -INF) {
cout << "YES" << '\n';
return;
}
}
cout << "NO" << '\n';
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
int T = 1; // cin >> T;
while (T--) {
solve();
}
}
