#include<bits/stdc++.h>
using namespace std;
const int MAXN = 21;
int n, m, a[MAXN], b[MAXN];
pair<int, int> dp[1<<MAXN];
bool ans;
int main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
for(int i = 0; i < m; i++){
cin >> b[i];
}
for(int msk = 1; msk < (1<<m); msk++){
for(int i = 0; i < m; i++){
if(msk&(1<<i)){
int om = msk-(1<<i);
if(a[dp[om].first+1] == dp[om].second+b[i]){
dp[msk] = make_pair(dp[om].first+1, 0);
break;
}
else{
dp[msk] = max(dp[msk], {dp[om].first, dp[om].second+b[i]});
}
}
}
if(dp[msk].first == n){
cout << "YES\n";
return 0;
}
}
cout << "NO\n";
}
# | 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... |