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
const int N = 20;
int n, m, dp[1ll << N], remain[1ll << N], arr[N], note[N];
bool set_bit(int mask, int k) { return mask & (1ll << k); }
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> arr[i];
for (int i = 0; i < m; i++) cin >> note[i];
for (int mask = 0; mask < (1ll << m); mask++) dp[mask] = -1;
dp[0] = 0;
for (int mask = 0; mask < (1ll << m); mask++) {
for (int i = 0; i < m; i++) {
if (!set_bit(mask, i)) continue;
if (dp[mask] == -1) continue;
int pmask = mask ^ (1ll << i), cur = arr[dp[pmask]];
if (remain[pmask] + note[i] < cur) {
dp[mask] = dp[pmask];
remain[mask] = remain[pmask] + note[i];
} else if (remain[pmask] + note[i] == cur) {
dp[mask] = dp[pmask] + 1;
remain[mask] = 0;
}
}
if (dp[mask] == n - 1) {
cout << "YES" << '\n';
return 0;
}
}
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... |