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;
void solve() {
int n, m;
cin >> n >> m;
vector<int> people(n);
for (int &p : people) cin >> p;
vector<int> bank_notes(m);
for (int &b : bank_notes) cin >> b;
vector<int> left_over(1 << m, -1);
vector<int> people_covered(1 << m, -1);
left_over[0] = 0;
people_covered[0] = 0;
for (int mask = 1; mask < 1 << m; mask++) {
for (int j = 0; j < m; j++) {
if (mask & 1 << j && people_covered[mask ^ (1 << j)] != -1) {
int rem = left_over[mask ^ (1 << j)] + bank_notes[j];
int people_ind = people_covered[mask ^ (1 << j)];
if (rem < people[people_ind]) {
left_over[mask] = rem;
people_covered[mask] = people_covered[mask ^ (1 << j)];
} else if (rem == people[people_ind]) {
left_over[mask] = 0;
people_covered[mask] = people_covered[mask ^ (1 << j)] + 1;
}
}
}
if (people_covered[mask] == n) {
cout << "YES" << endl;
return;
}
}
cout << "NO" << endl;
}
int main() {
solve();
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... |