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 int long long
#define sz(x) x.size()
#define pb push_back
#define F first
#define S second
#define nl '\n'
const int N = 3e5 + 1;
const int inf = 1e12;
const int mod = 1e9 + 7;
int n, m, a[21], b[21];
bool ch;
void rec( int j, vector< int >v )
{
if( j == m )
{
bool ch1 = true;
for( int i = 0; i < n; ++i )
if( a[i] != v[i] )
ch1 = false;
if( ch1 )
ch = true;
return;
}
rec(j + 1, v);
for( int i = 0; i < n; ++i )
{
v[i] += b[j];
rec(j + 1, v);
v[i] -= b[j];
}
}
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];
vector< int >v(n, 0);
rec(0, v);
cout <<(ch ? "YES\n" : "NO\n");
ch = false;
}
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... |