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;
int covered[(1<<20)] = {-1},leftover[(1<<20)] = {-1};
int main(){
int n,m,i,j,a[21],b[21];
cin >> n >> m;
for(i = 0;i < n;i++){
cin >> a[i];
}
sort(a,a+n);
for(i = 0;i < m;i++){
cin >> b[i];
}
leftover[0] = 0;
covered[0] = 0;
for(i = 1;i < (1 << m);i++){
for(j = 0;j < m;j++){
if(!i & (1 << j)){
int ih = i ^ (1 << j);
if(covered[ih] == -1) continue;
if(leftover[ih] + b[j] < a[covered[ih]]){
leftover[i] = leftover[ih] + b[j];
covered[i] = covered[ih];
}
if(leftover[ih] + b[j] < a[covered[ih]]){
leftover[i] = leftover[ih] + b[j];
covered[i] = covered[ih];
}
if(leftover[ih] + b[j] == a[covered[ih]]){
leftover[i] = 0;
covered[i] = covered[ih] + 1;
}
//cout << i << ' ' << covered[i] << ' ' << leftover[i] << ' ' << j << endl;
}
}
if(covered[i] == n){
cout << "YES";
return 0;
}
}
cout << "NO";
}
Compilation message (stderr)
bank.cpp: In function 'int main()':
bank.cpp:19:7: warning: suggest parentheses around operand of '!' or change '&' to '&&' or '!' to '~' [-Wparentheses]
19 | if(!i & (1 << j)){
| ^~
# | 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... |