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 <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
int main() {
int n, m;
std::cin >> n >> m;
std::vector<int> valores(n);
std::vector<int> notas(m);
for (int i = 0; i < n; ++i) {
std::cin >> valores[i];
}
for (int i = 0; i < m; ++i) {
std::cin >> notas[i];
}
std::vector<int> residual(1 << m, -1);
std::vector<int> cobertos(1 << m, -1);
residual[0] = 0;
cobertos[0] = 0;
bool possivel = false;
for (int s = 0; s < (1 << m); ++s) {
for (int p = 0; p < m; ++p) {
if ((s & (1 << p)) == 0) {
continue;
}
int ant = s & ~(1 << p);
// Verifica se o valor anterior é válido
if (cobertos[ant] == -1) {
continue;
}
int novo = residual[ant] + notas[p];
if (cobertos[ant] < 0 || cobertos[ant] >= n) {
continue;
}
int alvo = valores[cobertos[ant]];
if (novo < alvo) {
cobertos[s] = cobertos[ant];
residual[s] = novo;
} else if (novo == alvo) {
if (cobertos[ant] + 1 < n) {
cobertos[s] = cobertos[ant] + 1;
residual[s] = 0;
}
}
}
if (cobertos[s] == n) {
possivel = true;
}
}
if (possivel) {
std::cout << "YES" << std::endl;
} else {
std::cout << "NO" << std::endl;
}
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... |