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>
#define ff first
#define ss second
using namespace std;
int n,m,i,j;
vector<pair<int,int>> dp[(1<<20)];
int main(){
cin >> n >> m;
vector<int> a(n);
vector<int> b(m);
dp[0].push_back({0,0});
for(i=0;i<n;i++) cin >> a[i];
for(i=0;i<m;i++) cin >> b[i];
for(i=1;i<(1<<m);i++){
for(j=0;j<m;j++){
if(i&(1<<j)){
for(pair<int,int> l:dp[i^(1<<j)]){
if(l.ss+b[j]>a[l.ff]) continue;
if(l.ss+b[j]==a[l.ff]){
if(l.ff==n-1){
cout << "YES";
return 0;
}
dp[i].push_back({l.ff+1,0});
}
else dp[i].push_back({l.ff,l.ss+b[j]});
}
}
}
}
cout << "NO";
}
# | 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... |