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