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 int long long
#define aiiiii ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
const int N=2004876,INF=1e9+7;
int a[N],b[N],dp[N];
vector<int>v[30];
signed main(){
aiiiii
int n, m, i, j;
cin>>n>>m;
for(i=0;i<n;i++){
cin>>a[i];
}
for(i=0;i<m;i++){
cin>>b[i];
}
for(i=0;i<(1<<m);i++){
int sum=0;
for(j=0;j<m;j++){
if((i&(1<<j))!=0){
sum+=b[j];
}
}
for(j=0;j<n;j++){
if(sum==a[j])v[j].push_back(i);
}
}
for(i=1;i<N;i++){
dp[i]=-1;
}
for(i=0;i<n;i++){
for(j=(1<<m)-1;j>=0;j--){
if(dp[j]!=-1){
for(auto r:v[i]){
if(!(j&r)){
dp[j|r]=dp[j]+1;
}
if(dp[j|r]==n){
cout<<"YES";
return 0;
}
}
}
}
}
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... |