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 N, M;
vector<int> A, B;
int cur[(1 << 20)], lf[(1 << 20)];
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
memset(cur, -1, sizeof cur);
cin >> N >> M;
A = vector<int> (N), B = vector<int> (M);
for(int l = 0; l < N; l++) cin >> A[l];
for(int l = 0; l < M; l++) cin >> B[l];
cur[0] = 0;
for(int l = 1; l < (1 << M); l++) {
for(int i = 0; i < M; i++) {
if(!(l & (1 << i))) continue;
int mask = l ^ (1 << i);
if(cur[mask] == -1) continue;
int G = lf[mask] + B[i];
if(G == A[cur[mask]]) {
cur[l] = cur[mask] + 1;
lf[l] = 0;
}
else if(G < A[cur[mask]]) {
lf[l] = G; cur[l] = cur[mask];
}
}
if(cur[l] == 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... |