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 endl '\n'
#define debug(x) cerr << #x << " == " << (x) << '\n';
#define all(x) begin(x), end(x)
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int N, M;
cin >> N >> M;
vector<int> a(N), b(M);
for (auto& x : a) cin >> x;
for (auto& x : b) cin >> x;
partial_sum(all(a), begin(a));
string ans = "NO";
vector<int> dp(1 << M), sum(1 << M);
for (int j = 0; j < M; ++j) sum[1 << j] = b[j];
for (int mask = 0; mask < (1 << M); ++mask) {
int lsb = mask & -mask;
sum[mask] = sum[mask ^ lsb] + sum[lsb];
if (dp[mask] == N) {
ans = "YES";
break;
}
for (int j = 0; j < M; ++j) {
int nmask = mask | 1 << j, nsum = sum[mask] + b[j];
if ((mask >> j & 1) == 0 && nsum <= a[dp[mask]]) {
dp[nmask] = dp[mask] + (nsum == a[dp[mask]] ? 1 : 0);
}
}
}
cout << ans << endl;
exit(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... |