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 a[21], b[21];
int n, m;
void ye(){
cout << "YES\n";
exit(0);
}
void solve(int x, int suma, int mask, int j){
if (x>n) ye();
if (!suma){
solve(x+1,a[x+1], mask,0);
return;
}
int cnt = __builtin_popcount(mask);
if (m-cnt-1 < n-x) return;
for (int i = j; i < m; ++i){
if (m-cnt-1 < x-n) break;
if ((mask&(1 << i)) || b[i] > suma) continue;
solve(x, suma-b[i], mask^(1<<i),i+1);
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; ++i)
cin >> a[i];
for (int i = 0; i < m; ++i)
cin >> b[i];
solve(1, a[1], 0, 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... |