This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 21;
int a[MAXN], b[MAXN];
int dp[1 << MAXN], sum[1 << MAXN];
vector<int> v[MAXN];
int main(){
cin.tie(0)->sync_with_stdio(0);
int n, m; cin >> n >> m;
for(int i=0; i<n; i++){
cin >> a[i];
}
for(int i=0; i<m; i++){
cin >> b[i];
}
for(int s=1; s<(1 << m); s++){
int bit = __builtin_ctz(s);
sum[s] = sum[s ^ (1 << bit)] + b[bit];
}
for(int i=0; i<n; i++){
for(int s=0; s<(1 << m); s++){
if(sum[s] == a[i]) v[i].push_back(s);
}
}
for(int s=0; s<(1 << m); s++){
int i = min(n, dp[s] + 1);
for(auto x : v[i - 1]){
if((x & s) == 0){
dp[s ^ x] = max(dp[s ^ x], i);
}
}
}
cout << (dp[(1 << m) - 1] == n ? "YES" : "NO") << "\n";
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... |