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 ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e5 + 2;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for (int i = 0; i < n; i++) {
cin >> a[i];
if (i > 0) a[i] += a[i - 1];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
int M = (1 << m);
vector<int> sum(M);
for (int i = 0; i < M; i++) {
for (int j = 0; j < m; j++) {
if ((1 << j) & i) sum[i] += b[j];
}
}
vector<int> dp(M, -1e9);
dp[0] = 0;
for (int i = 1; i < M; i++) {
for (int j = 0; j < m; j++) {
if ((1 << j) & i) smax(dp[i], dp[i ^ (1 << j)]);
}
for (int j = 0; j < n; j++) if (a[j] == sum[i]) dp[i]++;
}
for (int i = 0; i < M; i++) {
if (dp[i] == n) {
cout << "YES" << '\n';
return 0;
}
}
cout << "NO" << '\n';
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... |