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 fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
#define f first
#define s second
#define MOD 998244353
#define LOGN 20
#define MAXN 1005
vector<bool> dp(1<<21, 0);
int main() {
fast
int N, M;
cin >> N >> M;
vector<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];
int mx_mask = (1<<M)-1;
vector<vector<int>> sums(1005, vector<int>());
for (int mask = 0; mask <= mx_mask; mask++) {
int sum = 0;
for (int i = 0; i < M; i++) {
if ((1<<i) & mask)
sum += B[i];
}
if (sum <= 1000)
sums[sum].push_back(mask);
}
dp[0] = 1;
for (int person = 0; person < N; person++) {
vector<bool> new_dp(1<<21, 0);
for (int mask = 0; mask <= mx_mask; mask++) {
if (!dp[mask])
continue;
for (auto u : sums[A[person]]) {
if ((mask & u) == 0)
new_dp[mask | u] = 1;
}
}
dp = new_dp;
}
for (auto u : dp) {
if (u) {
cout << "YES\n";
return 0;
}
}
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... |