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 int long long
#define ii pair<int,int>
#define f first
#define s second
#define mp make_pair
multiset<int> haha;
int n,m,BIT[21];
ii dp[1<<22];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
//freopen("bank.in","r",stdin);
//freopen("bank.out","w",stdout);
cin>>n>>m;
int a[n],b[m];
for (int i=0;i<n;i++)
cin>>a[i];
for (int i=0;i<m;i++)
cin>>b[i];
BIT[0]=1;ii newState;
for (int i=1;i<22;i++)
BIT[i]=BIT[i-1]<<1;
for (int mask=0;mask<BIT[m];mask++)
{
if (dp[mask].f==n)
{
cout<<"YES";
return 0;
}
for (int i=0;i<m;i++)
{
if (mask&BIT[i]) continue;
if (dp[mask].s+b[i]==a[dp[mask].f])
newState=mp(dp[mask].f+1,0);
else newState=mp(dp[mask].f,dp[mask].s+b[i]);
dp[mask|BIT[i]]=max(dp[mask|BIT[i]],newState);
}
}
cout<<"NO";
return 0;
}
Compilation message (stderr)
bank.cpp: In function 'int main()':
bank.cpp:25:15: warning: iteration 20 invokes undefined behavior [-Waggressive-loop-optimizations]
25 | BIT[i]=BIT[i-1]<<1;
| ~~~~~~^~~~~~~~~~~~
bank.cpp:24:19: note: within this loop
24 | for (int i=1;i<22;i++)
| ~^~~
# | 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... |