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 char nl = '\n';
signed main() {
int n;
int m;
std::cin >> n >> m;
int a[n], b[m];
for (int i = 0; i < n; i ++) cin >> a[i];
for (int j = 0; j < m; j ++) cin >> b[j];
vector<int> sum(1 << m, -1);
vector<int> dp(1 << m, -1);
sum[0] = 0;
dp[0] = 0;
for (int s = 0; s < (1 << m); s++) {
for (int last = 0; last < m; last++) {
if ((s & (1 << last)) == 0) { continue; }
int prev = s & ~(1 << last);
if (dp[prev] == -1) { continue; }
int new_amt = sum[prev] + b[last];
int curr_target = a[dp[prev]];
if (new_amt < curr_target) {
dp[s] = dp[prev];
sum[s] = new_amt;
}
else if (new_amt == curr_target) {
dp[s] = dp[prev] + 1;
sum[s] = 0;
}
}
if (dp[s] == n) {
cout << "YES" << nl;
return 0;
}
}
cout << "NO" << nl;
}
# | 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... |