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;
/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
*/
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
using ll = long long;
const int mod = 1e9+7;
void solve(int tc) {
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for (auto &x : a) cin >> x;
for (auto &x : b) cin >> x;
vector<vector<int>> sum(20001);
for (int mask = 0; mask < (1<<m); ++mask) {
int cur = 0;
for (int i = 0; i < m; ++i) {
if (mask&(1<<i)) {
cur += b[i];
}
}
sum[cur].push_back(mask);
}
vector<vector<int>> dp(n+1);
dp[0].push_back(0);
bool f = false;
for (int i = 0; i < n; ++i) {
vector<bool> vis(1<<m);
f = false;
for (int mask : sum[a[i]]) {
for (int pmask : dp[i]) {
if (!(mask&pmask) and !vis[mask|pmask]) {
vis[mask|pmask] = true;
dp[i+1].push_back(mask|pmask);
f = true;
}
}
}
}
cout << (f ? "YES\n" : "NO\n");
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int tc = 1;
//cin >> tc;
for (int i = 1; i <= tc; ++i) solve(i);
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... |