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;
#define forw(i,a,b) for(ll i=a;i<=b;i++)
#define forb(i,a,b) for(ll i=a;i>=b;i--)
#define fi first
#define se second
#define pb push_back
#define pu push
#define all(a) a.begin(),a.end()
#define getbit(mask,i) ((mask>>(i))&1)
#define getnum(i) (1<<(i))
#define add(a,b) (a)=((a)+(b))%mod
#define minimize(a,b) (a)=min((a),(b))
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll maxN=1e5+5;
const ll mod=1e9+7;
const ll oo=1e18;
const int tx[2]={0,1};
const int ty[2]={1,0};
ll n,m,a[22],b[22],dp[22][maxN],sum[maxN];
void solve()
{
cin>>n>>m;
forw(i,1,n) cin>>a[i];
forw(i,1,m) cin>>b[i];
forw(mask,1,(1<<m)-1)
forw(i,1,m)
if (mask>>(i-1)&1) sum[mask]+=b[i];
dp[0][0]=1;
forw(i,1,n)
forw(mask1,1,(1<<m)-1)
for(int mask2=mask1;mask2;mask2=((mask2-1)&mask1))
if (sum[mask2]==a[i])
dp[i][mask1]|=dp[i-1][mask1^mask2];
forw(mask,1,(1<<m)-1)
if (dp[n][mask])
{
cout<<"YES";
return;
}
cout<<"NO";
return;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
//freopen("bruh.inp","r",stdin);
//freopen("bruh.out","w",stdout);
int t=1; //cin>>t;
while(t--)
solve();
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... |