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(leftover[ih] + b[j] < a[covered[ih]]){
if(covered[i] <= covered[ih]){
leftover[i] = leftover[ih] + b[j];
covered[i] = covered[ih];
}
}
if(leftover[ih] + b[j] == a[covered[ih]]){
if(covered[i] <= covered[ih] + 1){
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";
}
# | 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... |