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 ii pair < int , int >
#define iii pair < int , ii>
#define iv pair < ii , ii >
#define fi first
#define se second
using namespace std;
const int N = 23;
const int mod = 1e9 + 7;
const int tt = 1e6;
const int base = 311;
int n, m;
int a[N], b[N], s[N];
bool dp[N][1 << N];
main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 0; i < n; i++) cin >> a[i];
for(int j = 0; j < m; j++) cin >> b[j];
for(int mask = 0; mask < (1 << m); mask++)
{
int sum = 0;
for(int j = 0; j < m; j++)
if((mask >> j) & 1)
sum += b[j];
s[mask] = sum;
}
for(int mask = 0; mask < (1 << m); mask++)
if(s[mask] == a[0])
dp[0][mask] = 1;
for(int i = 1; i < n; i++)
for(int mask = 0; mask < (1 << m); mask++){
for(int submask = mask; submask; submask = (submask - 1) & mask)
//cout << mask << " " << (mask ^ submask) << endl;
if(s[submask] == a[i])
dp[i][mask] |= dp[i - 1][mask ^ submask];
}
bool ans = 0;
for(int mask = 0; mask < (1 << m); mask++)
ans |= dp[n - 1][mask];
if(ans) cout << "YES";
else cout << "NO";
}
Compilation message (stderr)
bank.cpp:18:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
18 | main()
| ^~~~
# | 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... |