Submission #166624

#TimeUsernameProblemLanguageResultExecution timeMemory
166624TricksterBank (IZhO14_bank)C++14
71 / 100
1080 ms4752 KiB
//Suleyman Atayew

#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>

#define N 10010
#define ff first
#define ss second
#define pb push_back
#define ll long long
#define inf 1000000007
#define pii pair <ll, ll>

using namespace std;

ll sum;
ll n, m;
ll v[N];
ll arr[N];
vector <int> E[30];

int main()
{
	cin >> n >> m;
	
	for(int i = 1; i <= n; i++) cin >> v[i];
	
	for(int i = 0; i < m; i++) cin >> arr[i];
	
	E[0].pb(0);
	for(int i = 1; i <= n; i++) {
		for(int h = 0; h < (1<<m); h++) {
			int sum = 0;
			
			for(int j = 0; j < m; j++)
				if((h&(1<<j))) sum += arr[j];
			
			if(sum != v[i]) continue;
			
			for(auto j: E[i-1])
				if((j&h) == 0) E[i].pb(j|h);
		}
	}
	if(E[n].empty()) cout << "NO";
	else cout << "YES";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...