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;
const int mxN = 5e5 + 5;
#define int long long
#define MASK(n) (1 << (n))
#define BIT(mask,x) ((mask >> x) & 1)
const long long infll = 1e18 + 69;
int n;
int m;
int a[20];
int b[20];
int s[MASK(20)];
pair<int,int> dp[MASK(20)];
signed main () {
// freopen("bank.in","r",stdin);
// freopen("bank.out","w",stdout);
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
dp[0] = make_pair(0,0);
for (int mask = 0; mask < MASK(m); mask++)
for (int i = 0; i < m; i++) {
if(BIT(mask,i)) continue;
pair<int,int> new_state;
if(a[dp[mask].first] == dp[mask].second + b[i]) new_state = make_pair(dp[mask].first + 1,0);
else new_state = make_pair(dp[mask].first,dp[mask].second + b[i]);
dp[mask ^ MASK(i)] = max(dp[mask ^ MASK(i)],new_state);
}
bool kt = false;
for (int mask = 0; mask < MASK(m); mask++) if(dp[mask].first == n) {kt = true;break;}
if(kt) cout << "YES" << "\n";
else cout << "NO" << "\n";
}
# | 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... |