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<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N = 1e5 + 5;
typedef long long ll;
int n, m, a[25], b[25];
bool used[25];
void rec(int v, int sum, int cur) {
if (a[v] == sum) {
v++;
if (v == n + 1) {
cout << "YES";
exit(0);
}
sum = 0;
cur = 0;
}
for (int i = cur + 1; i <= m; i++) {
if (!used[i] && sum + b[i] <= a[v]) {
used[i] = 1;
rec(v, sum + b[i], i);
used[i] = 0;
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= m; i++) {
cin >> b[i];
}
rec(1, 0, 0);
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... |