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(){
int n, m;
cin >> n >> m;
vector<int> people(n), banknotes(m);
for(int &i : people) cin >> i;
for(int &i : banknotes) cin >> i;
vector<int> prefix_people(1<<m, -1), leftover(1<<m, -1);
prefix_people[0] = 0, leftover[0] = 0;
for(int s = 0; s<(1<<m); s++) {
for(int last = 0; last < m; last++) {
if((s & (1<<last)) == 0) continue;
int prev = s & ~(1<<last);
if(prefix_people[prev] == -1 || leftover[prev] == -1) continue;
int our_sum = leftover[prev] + banknotes[last];
int our_man = prefix_people[prev];
if(our_sum < people[our_man]) {
leftover[s] = our_sum;
prefix_people[s] = prefix_people[prev];
}
else if(our_sum == people[our_man]) {
prefix_people[s] = prefix_people[prev]+1;
leftover[s] = 0;
}
}
if(prefix_people[s] == n) {cout << "YES"; return 0;}
}
cout << "NO";
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... |