#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
#define f first
#define s second
#define MOD 998244353
#define LOGN 20
#define MAXN 1005
vector<int> dp(1<<20, 0);
int main() {
fast
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];
vector<vector<int>> sums(1005, vector<int>());
for (int mask = 0; mask < (1<<M); mask++) {
int sum = 0;
for (int i = 0; i < M; i++) {
if ((1<<i) & mask)
sum += B[i];
}
sums[sum].push_back(mask);
}
int mx_mask = (1<<M)-1;
dp[0] = 1;
for (int person = 0; person < N; person++) {
vector<int> new_dp(1<<20, 0);
for (int mask = 0; mask <= mx_mask; mask++) {
if (!dp[mask])
continue;
for (auto u : sums[A[person]]) {
if (mask & u == 0)
dp[mask | u] = 1;
}
}
dp = new_dp;
}
for (auto u : dp) {
if (u) {
cout << "YES\n";
return 0;
}
}
cout << "NO\n";
}
Compilation message
bank.cpp: In function 'int main()':
bank.cpp:44:30: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
44 | if (mask & u == 0)
| ~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
8532 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
8532 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
8848 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
8532 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |