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