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;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N, M;
cin >> N >> M;
vector<int> a(N), b(M);
for (int& ai : a) cin >> ai;
for (int& bi : b) cin >> bi;
vector<pair<int, int>> dp(1 << M, make_pair(-1, -1));
dp[0] = make_pair(0, 0);
for (int s = 0; s < (1 << M); s++) {
if (dp[s].first == -1) continue;
for (int nxt = 0; nxt < M; nxt++) {
if ((s & (1 << nxt))) continue;
if (dp[s].second + b[nxt] < a[dp[s].first]) {
dp[s + (1 << nxt)] = make_pair(dp[s].first, dp[s].second + b[nxt]);
} else if (dp[s].second + b[nxt] == a[dp[s].first]) {
dp[s + (1 << nxt)] = make_pair(dp[s].first + 1, 0);
}
}
if (dp[s].first == N) {
cout << "YES\n";
return 0;
}
}
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... |