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>
#define int long long
#define fi first
#define se second
using namespace std;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
vector<int> b(m);
for (int i = 0; i < m; i++) cin >> b[i];
vector<pair<int, int>> dp(1 << m, {-1, -1});
dp[0] = {0, 0};
for (int mask = 1; mask < (1 << m); mask++) {
for (int i = 0; i < m; i++) {
if (mask >> i & 1) {
auto [j, x] = dp[mask ^ (1 << i)];
if (j == -1) continue;
if (x + b[i] < a[j]) dp[mask] = {j, x + b[i]};
else if (x + b[i] == a[j]) dp[mask] = {j + 1, 0};
}
}
if (dp[mask].fi == n) {
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... |