#include <algorithm> #include <iostream> #include <vector> using namespace std; struct monster { int m,p; size_t i; bool operator< (const monster& o) const { if (m<p) return (o.m >= o.p) or (m < o.m); else if (m==p) return (o.m > o.p); else return (o.m > o.p) and (p > o.p); } }; bool solve(int HP, vector<monster>& M) { sort(M.begin(), M.end()); for(auto& m : M) { HP -= m.m; if (HP <= 0) return false; HP += m.p; } return true; } void onecase() { size_t N; int HP; cin >> N >> HP; vector<monster> M(N); for(size_t i=0;i<N;i++) { cin >> M[i].m >> M[i].p; M[i].i = i+1; } if (solve(HP, M)) { cout << "TAK" << endl; for (auto& m : M) cout << m.i << " "; cout << endl; } else cout << "NIE" << endl; } int main() { ios_base::sync_with_stdio(false); onecase(); /* size_t Z; cin >> Z; while(Z--) onecase(); */ 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 | #include <algorithm> #include <iostream> #include <vector> using namespace std; struct monster { int m,p; size_t i; bool operator< (const monster& o) const { if (m<p) return (o.m >= o.p) or (m < o.m); else if (m==p) return (o.m > o.p); else return (o.m > o.p) and (p > o.p); } }; bool solve(int HP, vector<monster>& M) { sort(M.begin(), M.end()); for(auto& m : M) { HP -= m.m; if (HP <= 0) return false; HP += m.p; } return true; } void onecase() { size_t N; int HP; cin >> N >> HP; vector<monster> M(N); for(size_t i=0;i<N;i++) { cin >> M[i].m >> M[i].p; M[i].i = i+1; } if (solve(HP, M)) { cout << "TAK" << endl; for (auto& m : M) cout << m.i << " "; cout << endl; } else cout << "NIE" << endl; } int main() { ios_base::sync_with_stdio(false); onecase(); /* size_t Z; cin >> Z; while(Z--) onecase(); */ return 0; } |