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 N = 1005;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<int> v(n), a(m);
for(auto& i: v) cin >> i;
for(auto& i: a) cin >> i;
vector<int> p(1<<m, -1), l(1<<m, -1);
p[0] = l[0] = 0;
for(int i = 1; i < (1<<m); i++)
{
for(int j = 0; j < m; j++)
{
if((i>>j)&1)
{
if(p[i^(1<<j)]==-1) continue;
int x = i^(1<<j), num = p[x];
if(l[x]+a[j]==v[num])
{
p[i] = p[x] + 1;
l[i] = 0;
break;
}
else if(l[x]+a[j] < v[num])
{
p[i] = p[x];
l[i] = l[x]+a[j];
}
}
}
if(p[i]==n)
{
cout << "YES\n";
break;
}
else if(i==(1<<m)-1)
{
cout << "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... |