제출 #1089466

#제출 시각아이디문제언어결과실행 시간메모리
1089466vjudge1은행 (IZhO14_bank)C++98
0 / 100
2 ms348 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...