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 n, m;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>m;
vector<int> a(n), b(m);
for (auto &x:a) cin>>x;
for (auto &x:b) cin>>x;
vector<int> dp(1<<m, -1), l(1<<m, 0);
dp[0]=0;
for (int i=1; i<(1<<m); i++)
{
for (int j=0; j<m; j++)
{
if ((i&(1<<j))==0) continue;
if (dp[i-(1<<j)]==-1) continue;
if (l[i-(1<<j)]+b[j]==a[dp[i-(1<<j)]]) dp[i]=dp[i-(1<<j)]+1, l[i]=0;
else if (l[i-(1<<j)]+b[j]<a[dp[i-(1<<j)]]) dp[i]=dp[i-(1<<j)], l[i]=l[i-(1<<j)]+b[j];
}
if (dp[i]==n)
{
cout<<"YES";
return 0;
}
}
cout<<"NO";
}
# | 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... |