Submission #671865

#TimeUsernameProblemLanguageResultExecution timeMemory
671865viwlesxqBank (IZhO14_bank)C++17
19 / 100
60 ms308 KiB
#include "bits/stdc++.h"
//#include "ext/pb_ds/assoc_container.hpp"
//#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
//using namespace __gnu_pbds;

//typedef long long ll;
//typedef string str;

#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
//#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//void freo(str x) {freopen((x + ".in").c_str(), "r", stdin);freopen((x + ".out").c_str(), "w", stdout);}

bool used[20];
bool got[20];
 
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, m;
	cin >> n >> m;
	vector <int> a(n), b(m);
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < m; i++) cin >> b[i];
	if (m < n) {
		cout << "NO\n";
		return 0;
	}
	sort(all(a));
	sort(all(b));
	for (int mask = 0; mask < (1 << m); mask++) {
		int sum = 0;
		for (int i = 0; i < m; i++) {
			if (mask & (1 << i) && !used[i]) {
				sum += b[i];
			}
		}
		bool flag = false;
		for (int i = 0; i < n; i++) {
			if (!got[i] && a[i] == sum) {
				flag = true;
				got[i] = true;
				break;
			}
		}
		if (flag) {
			for (int i = 0; i < m; i++) {
				if (mask & (1 << i) && !used[i]) {
					used[i] = true;
				}
			}
		}
	}
	bool flag = true;
	for (int i = 0; i < n; i++) {
		if (!got[i]) flag = false;
	}
	cout << (flag ? "YES" : "NO");
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...