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 maxmask = (1 << 20) + 5, maxn = 22;
int dp[maxmask], a[maxn], b[maxn], pref[maxn];
void solve(){
int n, m; cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
pref[0] = a[0];
for(int i = 1; i < n; i++) pref[i] = pref[i - 1] + a[i];
for (int mask = 0; mask < (1 << m); mask++) {
int sum = 0;
for (int i = 0; i < m; i++) {
if (mask & (1 << i)){
dp[mask] = max(dp[mask], dp[mask ^ (1 << i)]);
sum += b[i];
}
}
if (sum == pref[dp[mask]]) dp[mask]++;
}
if (dp[(1 << m) - 1] < n) cout << "NO\n";
else cout << "YES\n";
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
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... |