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;
const int maxn = 22, maxb = (1 << maxn);
int a[maxn], b[maxn], dp[maxb], left_val[maxb];
int n, m;
int main()
{
cin >> n >> m;
for(int i = 0; i < n; i++)
cin >> a[i];
for(int i = 0; i < m; i++)
cin >> b[i];
bool ch = 0;
for(int mask = 1; mask < (1 << m); mask++)
{
dp[mask] = 0;
//cout << mask << " : " << endl;
for(int i = 0; i < m; i++)
{
if(((mask >> i) & 1))
{
int mask2 = mask ^ (1 << i);
int tmp = dp[mask2];
int val = left_val[mask2] + b[i];
if(val > a[tmp])
continue;
// cout << mask2 << " , " << left_val[mask2] << endl;
if(tmp + (val == a[tmp]) >= dp[mask])
{
dp[mask] = tmp + (val == a[tmp]);
left_val[mask] = (val == a[tmp]) ? 0 : val;
}
}
}
if(dp[mask] == n)
ch = true;
}
if(ch)
cout << "YES" << '\n';
else
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... |