This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//
// Created by 42kangaroo on 08/01/2023.
//
#include "bits/stdc++.h"
using namespace std;
#define int long long
signed main() {
int n, m;
cin >> n >> m;
vector<int> a(n);
vector<int> b(m);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < m; ++i) {
cin >> b[i];
}
vector<pair<int,int>> dp(1 << m, {-1, -1});
dp[0] = {0, a[0]};
for (int i = 1; i < 1 << m; ++i) {
for (int j = 0; j < m; ++j) {
if (i & 1 << j) {
if (dp[i^(1<<j)].first != -1) {
if (dp[i^(1<<j)].second > b[j]) {
dp[i]= {dp[i^(1<<j)].first, dp[i^(1<<j)].second - b[j]};
}
if (dp[i^(1<<j)].second == b[j]) {
if (dp[i^(1<<j)].first == n - 1) {
cout << "YES\n";
return 0;
}
dp[i] = {dp[i^(1<<j)].first+1, a[dp[i^(1<<j)].first+1]};
}
}
}
}
}
cout << "NO\n";
}
# | 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... |