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