Submission #846327

#TimeUsernameProblemLanguageResultExecution timeMemory
846327Mr_HusanboyBank (IZhO14_bank)C++17
100 / 100
123 ms8792 KiB
#include <bits/stdc++.h>

using namespace std;

template<typename T>
int len(T &a){
	return a.size();
}

#define ll long long
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n, m; cin >> n >> m;
	vector<int> people(n), mon(m);

	for(auto &u : people) cin >> u;
	for(auto &u : mon) cin >> u;

	vector<pair<int,int>> dp(1 << m);
	bool ok = 0;
	for(int i = 1; i < (1 << m); i ++){
		for(int j = 0; j < m; j ++){
			if((i & (1 << j)) == 0) continue;
			auto op = dp[i ^ (1 << j)];
			if(op.ss + mon[j] < people[op.ff]){
				op.ss += mon[j];
			}else
			if(op.ss + mon[j] == people[op.ff]){
				op.ff ++; op.ss = 0;
			}
			dp[i] = max(dp[i], op);
		}
		if(dp[i].ff == n){
			ok = 1; break;
		}
	}
	cout << (ok ? "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...