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=2e6+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[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)
{
dp[mask]=-1;
forw(i,1,m)
if (mask>>(i-1)&1) sum[mask]+=b[i];
}
dp[0]=0;
forw(mask1,1,(1<<m)-1)
for(int mask2=mask1;mask2;mask2=((mask2-1)&mask1))
if (dp[mask1^mask2]!=-1 && sum[mask2]==a[dp[mask1^mask2]+1])
dp[mask1]=max(dp[mask1],dp[mask1^mask2]+1);
forw(mask,1,(1<<m)-1)
if (dp[mask]==n)
{
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... |