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 DEBUG false
using namespace std;
const int MAX_N = 20;
int a[MAX_N], b[MAX_N];
pair <int, int> dp[1<<MAX_N], tmp;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N, M;
cin >> N >> M;
for(int i = 0; i < N; i++) {
cin >> a[i];
}
for(int i = 0; i < M; i++) {
cin >> b[i];
}
for(int i = 0; i < (1<<M); i++) {
dp[i] = make_pair(-1, -1);
}
dp[0] = make_pair(0, 0);
for(int mask = 0; mask < (1<<M); mask++) {
for(int i = 0; i < M; i++) {
int prev = mask ^ (1<<i);
if(!(mask & (1<<i)) or dp[prev].first == -1) {
continue;
}
tmp = dp[prev];
if(tmp.second + b[i] > a[dp[prev].first]) {
continue;
}
tmp.second += b[i];
if(tmp.second == a[dp[prev].first]) {
tmp.first++;
tmp.second = 0;
}
dp[mask] = tmp;
if(tmp.first == N) {
cout << "YES";
return 0;
}
}
}
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... |