This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
const int N = 27;
const int oo = 1e18;
const int mod = 1e9 + 7;
int a[N], b[N], n, m;
bool f, vis[N];
void sol (int k, int mask) {
if (k > n) {
f = 1; return;
}
if (a[k] == 0) sol (k + 1, mask);
for (int i = 0; i < m; i++) {
if (((1 << i) & mask) == 0) {
if (a[k] >= b[i + 1]) {
mask += (1 << i);
if (!vis[mask]) {
a[k] -= b[i + 1];
sol (k, mask);
a[k] += b[i + 1];
sol (k, mask);
}
vis[mask] = 1;
} else break;
}
}
return;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= m; i++) cin >> b[i];
sort (a + 1, a + n + 1);
sort (b + 1, b + m + 1);
sol (1, 0);
if (f) cout << "YES\n";
else cout << "NO\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |