제출 #887149

#제출 시각아이디문제언어결과실행 시간메모리
887149BBart888은행 (IZhO14_bank)C++14
44 / 100
87 ms12756 KiB
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <queue>
#include <stack>
#include <cassert>
#include <cstring>
#include <climits>
#include <functional>
#include<cstdlib>
//#include "arc.h"
//#include "dreaming.h"


using namespace std;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long LL;



const int MAXN = 2e6 + 11; 
using ll = long long;
const ll mod1 = 1e9 + 7;
const ll mod2 = 1000000021;
const ll P = 31;



/*
void setIO(string name = "") {
	cin.tie(0)->sync_with_stdio(0); // see /general/fast-io
	if ((name.size())) {
		freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output
		freopen((name + ".out").c_str(), "w", stdout);
	}
}
*/



int n, m;
int a[MAXN];
int b[MAXN];
pair<int, int> dp[MAXN];
int flag;


int main()
{
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(false);
	//setIO("movie");
	
	cin >> n >> m;

	for (int i = 0; i < n; i++)
		cin >> a[i];

	for (int i = 0; i < m; i++)
		cin >> b[i];


	for (int mask = 0; mask < (1 << m); mask++)
	{
		for (int j = 0; j < m; j++)
		{
			pair<int, int> cur = dp[mask ^ (1 << j)];
			if (((1 << j) & mask) == 0)
				continue;
			int C = b[j];

			if (cur.second + C == a[cur.first])
			{
				dp[mask] = { cur.first + 1,0 };
			}
			else if(cur.second + C <= a[cur.first])
			{
				dp[mask] = max(dp[mask], make_pair(cur.first,cur.second + C));
			}
		}
	//	for (int j = 0; j < m; j++)
			//if ((1 << j) & mask)
				//cout << 1;
			//else
		//		cout << 0;
		
		//cout << " " << dp[mask].first << " " << dp[mask].second << '\n';
		if (dp[mask].first == n)
			flag = 1;
	}

	cout << (flag ? "YES\n" : "NO\n");





	

	return 0;
}






#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...