#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, m;
int val[20];
int bases[20];
vector<int> masks[1001];
void solve() {
cin >> n >> m;
for(int i = 0; i < n; i++) cin >> val[i];
sort(val, val+n);
reverse(val, val+n);
for(int i = 0; i < m; i++) cin >> bases[i];
for(int mask = 1; mask < (1<<m); mask++) {
int v = 0;
int t = mask;
while(v <= 1000 && t) {
v += bases[__builtin_ctz(t)];
t &= t-1;
}
if(v <= 1000) masks[v].push_back(mask);
}
unordered_set<int> ret;
ret.insert(0);
for(int i = 0; i < n; i++) {
unordered_set<int> nret;
for(int out2: ret) {
for(int out: masks[val[i]]) {
if(out&out2) continue;
if(__builtin_popcount(out | out2) + (n-i-1) > m) continue;
nret.insert(out | out2);
}
}
ret = nret;
}
if(ret.empty()) cout << "NO\n";
else cout << "YES\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |