#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<bool> dp(1<<21, 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];
int mx_mask = (1<<M)-1;
vector<vector<int>> sums(1005, vector<int>());
for (int mask = 0; mask <= mx_mask; mask++) {
int sum = 0;
for (int i = 0; i < M; i++) {
if ((1<<i) & mask)
sum += B[i];
}
sums[sum].push_back(mask);
}
dp[0] = 1;
for (int person = 0; person < N; person++) {
vector<bool> new_dp(1<<21, 0);
for (int mask = 0; mask <= mx_mask; mask++) {
if (!dp[mask])
continue;
for (auto u : sums[A[person]]) {
if ((mask & u) == 0)
new_dp[mask | u] = 1;
}
}
dp = new_dp;
}
for (auto u : dp) {
if (u) {
cout << "YES\n";
return 0;
}
}
cout << "NO\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
852 KB |
Output is correct |
2 |
Correct |
2 ms |
852 KB |
Output is correct |
3 |
Correct |
1 ms |
852 KB |
Output is correct |
4 |
Correct |
3 ms |
980 KB |
Output is correct |
5 |
Runtime error |
5 ms |
1876 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
852 KB |
Output is correct |
2 |
Correct |
1 ms |
852 KB |
Output is correct |
3 |
Runtime error |
1 ms |
980 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
980 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
852 KB |
Output is correct |
2 |
Correct |
2 ms |
852 KB |
Output is correct |
3 |
Correct |
1 ms |
852 KB |
Output is correct |
4 |
Correct |
3 ms |
980 KB |
Output is correct |
5 |
Runtime error |
5 ms |
1876 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |