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 <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, M;
cin >> N >> M;
vector<int> a(N);
for (int i = 0; i < N; i++) {
cin >> a[i];
}
vector<int> b(M);
for (int i = 0; i < M; i++) {
cin >> b[i];
}
sort(b.begin(), b.end());
do {
int i = 0;
for (int j = 0, s = 0; j < M; j++) {
if (s + b[j] <= a[i]) {
s += b[j];
}
if (a[i] == s) {
s = 0;
if (++i == N) {
cout << "YES\n";
return 0;
}
}
}
} while (next_permutation(b.begin(), b.end()));
cout << "NO\n";
return 6/22;
}
# | 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... |