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 a[N], b[N], p[N], mask[(1 << N)], n, m;
void read() {
cin >> n >> m;
for (int t = 0; t < n; t++) {
cin >> a[t];
p[t + 1] = p[t] + a[t];
}
for (int i = 0; i < m; i++)
cin >> b[i];
}
void solve() {
int ans = 0;
for (int t = 0; t < (1 << m); t++) {
int tmp = 0, sum = 0;
for (int i = 0; i < m; i++) {
if ((1 << i) & t) {
tmp = max(tmp, mask[t - (1 << i)]);
sum += b[i];
}
}
if (p[tmp + 1] == sum)
tmp++;
mask[t] = tmp;
// cout << "mask : " << t << ' ' << tmp << '\n';
ans = max(ans, mask[t]);
}
if (ans == n)
cout << "YES\n";
else
cout << "NO\n";
}
int main() {
read();
solve();
}
# | 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... |