제출 #751981

#제출 시각아이디문제언어결과실행 시간메모리
751981lucas_joel_han은행 (IZhO14_bank)C++14
100 / 100
86 ms8616 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int N, M;
	cin >> N >> M;
	vector<int> a(N), b(M);
	for (int& ai : a) cin >> ai;
	for (int& bi : b) cin >> bi;
	vector<pair<int, int>> dp(1 << M, make_pair(-1, -1));
	dp[0] = make_pair(0, 0);
	for (int s = 0; s < (1 << M); s++) {
		if (dp[s].first == -1) continue;
		for (int nxt = 0; nxt < M; nxt++) {
			if ((s & (1 << nxt))) continue;
			if (dp[s].second + b[nxt] < a[dp[s].first]) {
				dp[s + (1 << nxt)] = make_pair(dp[s].first, dp[s].second + b[nxt]);
			} else if (dp[s].second + b[nxt] == a[dp[s].first]) {
				dp[s + (1 << nxt)] = make_pair(dp[s].first + 1, 0);
			}
		}
		if (dp[s].first == N) {
			cout << "YES\n";
			return 0;
		}
	}
	cout << "NO\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...