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 main(){
int n, m; cin >> n >> m;
int a[n], b[m];
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < m; i++) cin >> b[i];
vector<int> cover(1 << m, -1), left(1 << m, -1);
left[0] = cover[0] = 0;
for(int mask = 1; mask < (1 << m); mask++){
for(int last = 0; last < m; last++){
if(!(mask & (1 << last))) continue;
int p = mask & ~(1 << last);
if(cover[p] == -1) continue;
int new_ = left[p] + b[last], target = a[cover[p]];
if(new_ < target){
cover[mask] = cover[p];
left[mask] = new_;
}else if(new_ == target){
cover[mask] = cover[p] + 1;
left[mask] = 0;
}
}
if(cover[mask] == 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... |