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 <vector>
#include <algorithm>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector <int> sums(n);
for (int i = 0; i < n; i++)
cin >> sums[i];
vector <int> notes(m);
for (int i = 0; i < m; i++)
cin >> notes[i];
if (n == 1) {
for (int i = 0; i < (1 << m); i++) {
int s = 0;
for (int j = 0; j < m; j++) {
if (i & (1 << j))
s += notes[j];
}
if (s == sums[0]) {
cout << "YES\n";
return 0;
}
}
cout << "NO\n";
return 0;
} else {
sort(notes.begin(), notes.end());
do {
int p = 0, tot = 0;
for (int i = 0; i < m && p < n; i++) {
tot += notes[i];
if (tot == sums[p]) {
p++;
tot = 0;
} else if (tot > sums[p])
break;
}
if (p >= n) {
cout << "YES\n";
return 0;
}
} while (next_permutation(notes.begin(), notes.end()));
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... |