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 N = 20 + 2;
int n, m, a[N], b[N], dp[1<<N], ps[N];
void read_input() {
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < m; i++)
cin >> b[i];
}
void solve() {
ps[0] = a[0];
for (int i = 1; i < n; i++)
ps[i] = ps[i - 1] + a[i];
dp[0] = -1;
for (int msk = 1; msk < (1 << m); msk++) {
int mx = -2;
int sum = 0;
for (int i = 0; i < m; i++)
if (msk >> i & 1) {
mx = max(mx, dp[msk ^ (1 << i)]);
sum += b[i];
}
if (sum == ps[mx + 1])
dp[msk] = mx + 1;
else
dp[msk] = mx;
}
for (int msk = 0; msk < (1 << m); msk++) {
if (dp[msk] == n - 1) {
cout << "YES" << endl;
return ;
}
}
cout << "NO" << endl;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
read_input(), solve();
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... |