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 nl '\n'
#define pb push_back
int n, m, a[20], b[20];
map<int, vector< int >>mp;
bool ch;
void rec( int i, int msk )
{
if( i == n )
{
ch = true;
return;
}
for( int x: mp[a[i]] )
{
bool ch1 = true;
for( int k = 0; k < 20; ++k )
if( ((1 << k) & x) && ((1 << k) & msk) )
{
ch1 = false;
break;
}
if( ch1 )
rec(i + 1, msk + x);
}
}
void solve()
{
cin >>n >>m;
for( int i = 0; i < n; ++i )
cin >>a[i];
for( int j = 0; j < m; ++j )
cin >>b[j];
for( int mask = 0; mask < (1 << m); ++mask )
{
int sum = 0;
for( int i = 0; i < m; ++i )
if( (1 << i) & mask )
sum += b[i];
mp[sum].pb( mask );
}
rec(0, 0);
cout <<(ch ? "YES" : "NO");
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int T = 1;
// cin >>T;
while( T-- )
solve();
}
# | 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... |