이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |