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;
#define vi vector <int>
#define pb push_back
const int MAX_N = 21;
int n, m;
vi people(MAX_N);
vi banknotes(MAX_N);
vi people_cov(1 << MAX_N, -1);
vi leftover(1 << MAX_N, -1);
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for(int i = 0; i < n; i++){
cin >> people[i];
}
for(int i = 0; i < m; i++){
cin >> banknotes[i];
}
people_cov[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(people_cov[prev] == -1) continue;
int new_amt = leftover[prev] + banknotes[last];
int curr_target = people[people_cov[prev]];
if(new_amt < curr_target){
people_cov[s] = people_cov[prev];
leftover[s] = new_amt;
}
if(new_amt == curr_target){
people_cov[s] = people_cov[prev] + 1;
leftover[s] = 0;
}
}
if(people_cov[s] == n){
cout << "YES\n";
return 0;
}
}
cout << "NO\n";
}
# | 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... |