Submission #1138545

#TimeUsernameProblemLanguageResultExecution timeMemory
1138545AgageldiBank (IZhO14_bank)C++20
19 / 100
1 ms328 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define N 600005
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()

ll T, n, a[N], t, m, b[N], vis[N];
void solve(int x) {
	if(x == n + 1) {
		cout << "YES\n";
		exit(0);
	}
	vector <int> pos;
	pos.clear();
	for(int j = 1; j <= a[x] + 1000; j++) {
		pos.pb(0);
	}
	pos[0] = 1;
	for(int j = 1; j <= m; j++) {
		if(vis[j]) continue;
		for(int k = 1000; k >= 0; k--) {
			if(pos[k] != 0 && pos[k + b[j]] == 0) {
				pos[k + b[j]] = j;
			}
		}
	}
	if(!pos[a[x]]) return;
	int tt = a[x];
	while(tt > 0) {
		vis[pos[tt]] = 1;
		tt -= b[pos[tt]];
	}
	solve(x + 1);
	tt = a[x];
	while(tt > 0) {
		vis[pos[tt]] = 0;
		tt -= b[pos[tt]];
	}
}

int main () {
	cin >> n >> m;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for(int i = 1; i <= m; i++) {
		cin >> b[i];
	}
	solve(1);
	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...