Submission #1088507

#TimeUsernameProblemLanguageResultExecution timeMemory
1088507vjudge1Bank (IZhO14_bank)C++17
100 / 100
86 ms8656 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); if (cobertos[ant] == -1) { continue; } int novo = residual[ant] + notas[p]; int alvo = valores[cobertos[ant]]; if (novo < alvo) { cobertos[s] = cobertos[ant]; residual[s] = novo; } else if (novo == alvo) { 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...