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>
#define ll long long
#define vi vector<int>
#define vvll vector<vector<ll>>
#define pb push_back
#define pii pair<int,int>
#define X first
#define Y second
#define N 100005
using namespace std;
const int MOD=1e9+7;
const int mod=1e9+9;
const int p=31;
bool dp[1<<20][21];
int A[21],sum[1<<20],n,m,B[21],k;
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin>>n>>m;
for(int i=1;i<=n;++i){cin>>A[i];A[i]+=A[i-1];}
for(int i=0;i<m;++i){cin>>B[i];dp[1<<i][0]=1;}
for(int i=1;i<(1<<m);++i)
{
sum[i]=sum[i^(i&-i)]+B[__lg(i&-i)];
k=0;
for(int j=1;j<=n;++j)if(sum[i]==A[j]){k=j;}
if(k&&dp[i][k-1])dp[i][k]=1;
for(int j=0;j<m;++j)
if(!(i&(1<<j)))
for(int k=0;k<=n;++k)
dp[i^(1<<j)][k]|=dp[i][k];
}
if(dp[(1<<m)-1][n])cout<<"YES\n";
else 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... |