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>
#define ll long long
using namespace std;
const ll mod = 1e9 + 7;
struct elem_t {
int met, rem;
};
int main() {
// ifstream cin("valleys.in");
// ofstream cout("valleys.out");
int n, m, i, j;
cin >> n >> m;
vector<int> sal(n), note(m);
for (i = 0; i < n; i++) cin >> sal[i];
for (i = 0; i < m; i++) cin >> note[i];
if (n > m) {
cout << "NO";
return 0;
}
int M = 1 << m;
vector<elem_t> dp(M, {0, 0});
elem_t newe;
int res;
for (i = 1; i < M; i++) {
for (j = 0; j < m; j++) {
if (not (i & (1 << j))) continue;
res = dp[i - (1 << j)].rem + note[j];
if (res > sal[dp[i - (1 << j)].met]) continue;
else if (res == sal[dp[i - (1 << j)].met]) {
newe.met = dp[i - (1 << j)].met + 1;
newe.rem = 0;
} else {
newe.met = dp[i - (1 << j)].met;
newe.rem = res;
}
if (newe.met == n) {
cout << "YES";
return 0;
}
if (newe.met > dp[i].met) dp[i] = newe;
else if (newe.met == dp[i].met) dp[i].rem = max(dp[i].rem, newe.rem);
}
}
cout << "NO";
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... |