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;
constexpr int NMAX = 21;
int dp[(1<<NMAX)];
int last[(1<<NMAX)];
int N, M;
int A[NMAX], B[NMAX];
void Read () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> M;
for (int i = 1; i <= N; ++ i )
cin >> A[i];
for (int i = 0; i < M; ++ i )
cin >> B[i];
}
void Solve () {
dp[0] = 0;
last[0] = 0;
for (int mask = 1; mask < (1<<M); ++ mask ) {
for (int i = 0; i < M; ++ i ) {
if ((mask&(1<<i)) == 0) continue;
int bef_state = mask^(1<<i);
int current = last[bef_state] + B[i];
if (current > A[dp[bef_state]+1]) continue;
int new_reach = dp[bef_state] + (current == A[dp[bef_state]+1]);
int new_last = (current == A[dp[bef_state]+1] ? 0 : current);
if (new_reach > dp[mask]) {
dp[mask] = new_reach;
last[mask] = new_last;
}
else if (new_reach == dp[mask]) last[mask] = new_last;
}
if (dp[mask] == N) {
cout << "YES\n";
return;
}
}
cout << "NO\n";
}
int main () {
Read();
Solve();
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... |