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;
typedef long long ll;
int n, m, a[20], b[20];
vector<int> masks[20001];
bool search(int i, int cur_mask)
{
if (i == n)
return true;
for (int mask : masks[a[i]])
if ((cur_mask & mask) == 0 && search(i + 1, cur_mask | mask))
return true;
return false;
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < m; i++)
cin >> b[i];
for (int mask = 0; mask < (1 << m); mask++)
{
int sum = 0;
for (int i = 0; i < m; i++)
if (mask & (1 << i))
sum += b[i];
masks[sum].push_back(mask);
}
for (int sum = 0; sum <= 20000; sum++)
sort(masks[sum].begin(), masks[sum].end(), [] (const int &x, const int &y) {return __builtin_popcount(x) > __builtin_popcount(y);});
cout << (search(0, 0) ? "YES\n" : "NO\n");
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... |