#include <iostream> #include <vector> #include <algorithm> using namespace std; struct monster { int a; int h; int df; int nr; }; bool comp(monster a, monster b) { return a.a < b.a; } bool compR(monster a, monster b) { return a.a > b.a; } inline ostream& operator<< (ostream& stream, const monster& p) { stream << p.nr; return stream; } vector<monster> good; vector<monster> bad; int n,z; bool attack(monster& m) { if (m.a >= z) { return false; } else { z = z + m.df; return true; } } int main() { cin >> n >> z; int result[n]; for(int i1 = 1 ; i1 <= n ; i1++) { monster m; cin >> m.a >> m.h; m.df = m.h - m.a; m.nr = i1; if( m.df >= 0) { good.push_back(m); } else { bad.push_back(m); } } sort(good.begin(), good.end(), comp); vector<monster>::iterator it; int count = 0; bool isFaild = false; for (it=good.begin(); it<good.end(); it++) { if(attack(*it)) { result[count] = (*it).nr; count++; } else { isFaild = true; break; } } if(!isFaild) { sort(bad.begin(), bad.end(), compR); for(it=bad.begin(); it<bad.end(); it++) { if(attack(*it)) { result[count] = (*it).nr; count++; } else { isFaild = true; break; } } } if( !isFaild ) { cout << "TAK\n"; cout << result[0]; for(int i = 1 ; i < n ; i++) { cout << " " << result[i]; } } else { cout << "NIE"; } 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 111 112 113 114 115 116 117 118 119 120 121 | #include <iostream> #include <vector> #include <algorithm> using namespace std; struct monster { int a; int h; int df; int nr; }; bool comp(monster a, monster b) { return a.a < b.a; } bool compR(monster a, monster b) { return a.a > b.a; } inline ostream& operator<< (ostream& stream, const monster& p) { stream << p.nr; return stream; } vector<monster> good; vector<monster> bad; int n,z; bool attack(monster& m) { if (m.a >= z) { return false; } else { z = z + m.df; return true; } } int main() { cin >> n >> z; int result[n]; for(int i1 = 1 ; i1 <= n ; i1++) { monster m; cin >> m.a >> m.h; m.df = m.h - m.a; m.nr = i1; if( m.df >= 0) { good.push_back(m); } else { bad.push_back(m); } } sort(good.begin(), good.end(), comp); vector<monster>::iterator it; int count = 0; bool isFaild = false; for (it=good.begin(); it<good.end(); it++) { if(attack(*it)) { result[count] = (*it).nr; count++; } else { isFaild = true; break; } } if(!isFaild) { sort(bad.begin(), bad.end(), compR); for(it=bad.begin(); it<bad.end(); it++) { if(attack(*it)) { result[count] = (*it).nr; count++; } else { isFaild = true; break; } } } if( !isFaild ) { cout << "TAK\n"; cout << result[0]; for(int i = 1 ; i < n ; i++) { cout << " " << result[i]; } } else { cout << "NIE"; } return 0; } |