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 = 20;
int pre[N],dp[1<<N],b[N+2];
int main()
{
int n,m;
cin>>n>>m;
for(int i = 1;i <= n;i++)
{
cin>>pre[i];
pre[i] += pre[i-1];
}
for(int i = 0;i < m;i++)cin>>b[i];
for(int i = 0;i < (1<<m);i++)
{
int s = 0;
for(int j = 0;j < m;j++)if(i&(1<<j))s += b[j];
for(int j = 0;j < m;j++)
{
if(i&(1<<j))
{
if(pre[dp[i^(1<<j)] + 1] == s)dp[i] = max(dp[i],dp[i^(1<<j)]+1);
else dp[i] = max(dp[i],dp[i^(1<<j)]);
}
}
}
if(dp[(1<<m) - 1] < n)cout<<"NO";
else cout<<"YES";
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... |