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;
int main() {
int n, m;
cin >> n >> m;
long long dp[(1 << m) + 10];
memset(dp, -1, sizeof dp);
long long a[n + 5], b[m + 5], pt[n + 5];
for (int i = 0; i < n; i++) {
cin >> a[i];
pt[i] = (i == 0? a[i]: pt[i - 1] + a[i]);
}
for (int i = 0; i < m; i++)
cin >> b[i];
for (int mask = 0; mask < (1 << m); mask++) {
long long sum = 0;
for (int i = 0; i < m; i++) {
if ((1 << i) & mask)
dp[mask] = max(dp[mask], dp[mask ^ (1 << i)]), sum += b[i];
}
if (sum == pt[dp[mask] + 1])
dp[mask]++;
}
if (dp[(1 << m) - 1] >= n - 1)
cout << "YES\n";
else
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... |