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;
#define long long int
int n,m;
vector<int> a,b;
vector<vector<int>> dp;
bool f(int i, int mask){
if(i == n)return true;
bool sol = false;
for(int newMask : dp[i]){
if((mask&newMask) != 0) continue;
sol = max(sol,f(i+1,mask|newMask));
if(sol)return true;
}
return sol;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
a.resize(n);
b.resize(m);
dp.resize(n);
for(int i=0; i<n; i++){
cin >> a[i];
}
for(int i=0; i<m; i++){
cin >> b[i];
}
for(int i=0; i<n; i++){
for(int mask = 1; mask < (1<<m); mask++){
int suma = 0;
for(int j=0; j<m; j++){
if(mask&(1<<j)){
suma += b[j];
if(suma > a[i])break;
}
}
if(suma == a[i]){
dp[i].push_back(mask);
}
}
}
if(f(0,0)){
cout << "YES\n";
}else 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... |