#include <iostream> #include <vector> #include <map> struct boss { unsigned int _hit; unsigned int _heal; }; std::istream& operator>>(std::istream& stream, boss& b) { stream >> b._hit >> b._heal; return stream; } std::ostream& operator<<(std::ostream& stream, boss& b) { stream << b._hit << " " << b._heal; return stream; } int main() { std::ios_base::sync_with_stdio(0); unsigned int bosses_count; std::cin >> bosses_count; unsigned int health; std::cin >> health; std::vector<boss> bosses(bosses_count); std::vector<int> order; order.reserve(bosses_count); std::multimap<unsigned int, unsigned int> hit_to_boss_for_positive_bosses; typedef std::multimap<unsigned int, unsigned int> loss_to_boss; std::map<unsigned int, loss_to_boss, std::greater<unsigned int>> hit_to_boss_for_negative_bosses; unsigned int total_heal = 0; unsigned int total_hit = 0; bool something_killed = false; for (unsigned int i = 0; i < bosses_count; ++i) { boss& b = bosses[i]; std::cin >> b; if (b._heal >= b._hit) { if (b._hit < health) { order.push_back(i); health += b._heal - b._hit; something_killed = true; continue; } hit_to_boss_for_positive_bosses.insert( std::make_pair(b._hit, i)); } else { total_heal += b._heal; total_hit += b._hit; loss_to_boss& l2b = hit_to_boss_for_negative_bosses[b._hit]; l2b.insert(std::make_pair(b._hit - b._heal, i)); } } if (something_killed == false || total_heal + health < total_hit) { std::cout << "NIE" << std::endl; return 0; } for (const auto& hit_and_boss : hit_to_boss_for_positive_bosses) { if (hit_and_boss.first >= health) { std::cout << "NIE" << std::endl; return 0; } order.push_back(hit_and_boss.second); boss& b = bosses[hit_and_boss.second]; health += b._heal - b._hit; } for (const auto& hit_and_l2b : hit_to_boss_for_negative_bosses) { const unsigned int& hit = hit_and_l2b.first; for (const auto& l2b : hit_and_l2b.second) { if (hit >= health) { std::cout << "NIE" << std::endl; return 0; } order.push_back(l2b.second); boss& b = bosses[l2b.second]; health -= b._hit - b._heal; } } std::cout << "TAK" << std::endl; std::cout << order.front() + 1; for (unsigned int i = 1; i < bosses_count; ++i) { std::cout << " " << order[i] + 1; } std::cout << std::endl; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | #include <iostream> #include <vector> #include <map> struct boss { unsigned int _hit; unsigned int _heal; }; std::istream& operator>>(std::istream& stream, boss& b) { stream >> b._hit >> b._heal; return stream; } std::ostream& operator<<(std::ostream& stream, boss& b) { stream << b._hit << " " << b._heal; return stream; } int main() { std::ios_base::sync_with_stdio(0); unsigned int bosses_count; std::cin >> bosses_count; unsigned int health; std::cin >> health; std::vector<boss> bosses(bosses_count); std::vector<int> order; order.reserve(bosses_count); std::multimap<unsigned int, unsigned int> hit_to_boss_for_positive_bosses; typedef std::multimap<unsigned int, unsigned int> loss_to_boss; std::map<unsigned int, loss_to_boss, std::greater<unsigned int>> hit_to_boss_for_negative_bosses; unsigned int total_heal = 0; unsigned int total_hit = 0; bool something_killed = false; for (unsigned int i = 0; i < bosses_count; ++i) { boss& b = bosses[i]; std::cin >> b; if (b._heal >= b._hit) { if (b._hit < health) { order.push_back(i); health += b._heal - b._hit; something_killed = true; continue; } hit_to_boss_for_positive_bosses.insert( std::make_pair(b._hit, i)); } else { total_heal += b._heal; total_hit += b._hit; loss_to_boss& l2b = hit_to_boss_for_negative_bosses[b._hit]; l2b.insert(std::make_pair(b._hit - b._heal, i)); } } if (something_killed == false || total_heal + health < total_hit) { std::cout << "NIE" << std::endl; return 0; } for (const auto& hit_and_boss : hit_to_boss_for_positive_bosses) { if (hit_and_boss.first >= health) { std::cout << "NIE" << std::endl; return 0; } order.push_back(hit_and_boss.second); boss& b = bosses[hit_and_boss.second]; health += b._heal - b._hit; } for (const auto& hit_and_l2b : hit_to_boss_for_negative_bosses) { const unsigned int& hit = hit_and_l2b.first; for (const auto& l2b : hit_and_l2b.second) { if (hit >= health) { std::cout << "NIE" << std::endl; return 0; } order.push_back(l2b.second); boss& b = bosses[l2b.second]; health -= b._hit - b._heal; } } std::cout << "TAK" << std::endl; std::cout << order.front() + 1; for (unsigned int i = 1; i < bosses_count; ++i) { std::cout << " " << order[i] + 1; } std::cout << std::endl; return 0; } |