Submission #1107246

#TimeUsernameProblemLanguageResultExecution timeMemory
1107246vjudge1Bank (IZhO14_bank)C++17
19 / 100
1079 ms452 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...