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 MAXV=1005,MAXN=20;
vector<int> v[MAXV];
int a[MAXN],b[MAXN];
bool dp[MAXN][1<<MAXN];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(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 i=0;i<(1<<m);i++){
int uang=0;
for(int j=0;j<m;j++){
if((1<<j) & i)uang+=b[j];
}
if(uang>1000)continue;
v[uang].push_back(i);
}
for(auto isi : v[a[0]])dp[0][isi]=true;
for(int i=1;i<n;i++){
bool ada=false;
vector<int> bisa;
for(int mask=0;mask<(1<<m);mask++){
if(!dp[i-1][mask])continue;
for(auto isi : v[a[i]]){
if((mask&isi)==0){
dp[i][mask|isi]=true;
ada=true;
}
}
}
if(!ada)break;
}
bool yes=0;
for(int mask=0;mask<(1<<m);mask++)yes|=dp[n-1][mask];
if(yes)cout << "YES\n";
else cout << "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... |