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>
#ifdef VSLOCAL
#include "debug/d.h"
#endif
#ifdef LOCAL
#include "../../debug/d.h"
#endif
using namespace std;
using ll = long long;
using ld = long double;
#if defined(LOCAL) || defined(VSLOCAL)
#define dbg(...) line_info(__LINE__, #__VA_ARGS__), dbg1(__VA_ARGS__)
void nline() { cerr << '\n'; }
#else
#define dbg(...) 0
void nline() {}
#endif
int main() {
ios::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("log.txt", "w", stderr);
#endif
int N, M;
cin >> N >> M;
vector<int> a (N);
for (int i = 0; i < N; ++i) {
cin >> a[i];
}
vector<int> b (M);
for (int i = 0; i < M; ++i) {
cin >> b[i];
}
vector<pair<int, int>> dp (1 << M);
for (int i = 1; i < (1 << M); ++i) {
for (int j = 0; j < M; ++j) {
if (i & (1 << j)) {
auto [num, val] = dp[i ^ (1 << j)];
if (num == N) {
dp[i] = {N, 0};
break;
}
if (val + b[j] > a[num]) dp[i] = max(dp[i], dp[i ^ (1 << j)]);
else if (val + b[j] == a[num]) dp[i] = max(dp[i], {num + 1, 0});
else dp[i] = max(dp[i], {num, val + b[j]});
}
}
}
if (dp[(1 << M) - 1].first == N) cout << "YES\n";
else cout << "NO\n";
}
# | 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... |