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 ppl[n], bank[m];
for(int i=0; i<n; i++)
cin >> ppl[i];
for(int i=0; i<m; i++)
cin >> bank[i];
vector<int> covered(1<<m, -1);
vector<int> leftover(1<<m, -1);
covered[0] = 0;
leftover[0] = 0;
for(int mask=1; mask<(1<<m); mask++){
for(int i=0; i<m; i++){
if((mask&(1<<i)) == 0) continue;
int prev = mask^(1<<i);
if(covered[prev] == -1) continue;
int amt = leftover[prev] + bank[i];
int target = ppl[covered[prev]];
if(amt < target){
covered[mask] = covered[prev];
leftover[mask] = amt;
}else if(amt == target){
covered[mask] = covered[prev] + 1;
leftover[mask] = 0;
}
}
// if(covered[mask] == n){
// cout << "YES";
// return 0;
// }
}
for(int i=0; i<(1<<n); i++){
if(covered[i] == 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... |