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 = 25;
int n, m, a[N], b[N], dp[1 << N], sum[N];
void solve() {
for (int i = 0; i < n; i++)
sum[i + 1] = sum[i] + a[i];
for (int msk = 0; msk < (1 << m); msk++) {
int s = 0;
for (int i = 0; i < m; i++)
if ((msk >> i) & 1)
dp[msk] = max(dp[msk], dp[msk ^ (1 << i)]), s += b[i];
dp[msk] += (s == sum[dp[msk] + 1]);
}
cout << (dp[(1 << m) - 1] == n? "YES": "NO");
}
void read() {
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < m; i++)
cin >> b[i];
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
read(), 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... |