#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, m; cin >> n >> m;
vector<int> a(n); for (auto &x: a) cin >> x;
vector<int> b(m); for (auto &x: b) cin >> x;
map<pair<vector<int>, int>, bool> memo;
function<bool(vector<int>, int)> solve = [&](vector<int> s, int m) -> bool {
if (s.size() == 0) return true;
if (m == -1) return false;
if (memo.count({s, m})) return memo[{s, m}];
int n = s.size();
int note = b[m];
bool ans = solve(s, m - 1);
for (int i = 0; i < n; i++) {
vector<int> curr;
for (int j = 0; j < n; j++)
if (i == j && s[j] == note) continue;
else if (i == j) curr.push_back(s[j] - note);
else curr.push_back(s[j]);
ans |= solve(curr, m - 1);
}
return memo[{s, m}] = ans;
};
if (solve(a, m - 1)) cout << "YES";
else cout << "NO";
}
# | 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... |