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>
#include <unordered_map>
#include <vector>
#define ll long long
#define ull unsigned long long
#define pii std::pair<int, int>
#define IO (std::string) ""
std::ifstream fin(IO + ".in");
std::ofstream fout(IO + ".out");
#define NMAX 21
int n, m;
int a[NMAX], b[NMAX];
void citire() {
std::cin >> n >> m;
for (int i = 0; i < n; i++)
std::cin >> a[i];
for (int i = 0; i < m; i++)
std::cin >> b[i];
}
int main() {
citire();
std::vector<int> curr(1 << m, -1), l(1 << m, -1);
curr[0] = l[0] = 0;
for (int mask = 0; mask < (1 << m); mask++) {
for (int j = 0; j < m; j++) {
if (!(mask & (1 << j)))
continue;
int prev = mask ^ (1 << j);
if (curr[prev] == -1)
continue;
int aux = l[prev] + b[j];
if (aux < a[curr[prev]]) {
curr[mask] = curr[prev];
l[mask] = aux;
} else
if (aux == a[curr[prev]]) {
curr[mask] = curr[prev] + 1;
l[mask] = 0;
}
}
if (curr[mask] == n) {
std::cout << "YES";
return 0;
}
}
std::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... |