#include <iostream> #include <algorithm> #include <sstream> using namespace std; #define MONSTERS 100000 class monster{ public: int d, a, zysk, sign, id; bool operator<(const monster& right)const{ if (sign > right.sign)return true; if (sign < right.sign)return false; if (sign > 0) return d < right.d; return a > right.a; } }; monster monsters[MONSTERS]; int main(){ cin.sync_with_stdio(false); int n, z; cin >> n >> z; for (int i = 0; i < n; i++){ cin >> monsters[i].d >> monsters[i].a; monsters[i].zysk = monsters[i].a - monsters[i].d; if (monsters[i].zysk>0){ monsters[i].sign = 1; }else if (monsters[i].zysk<0){ monsters[i].sign = -1; } else { monsters[i].sign = 0; } monsters[i].id = i + 1; } sort(monsters,monsters+n); stringstream sresult; for (int i = 0; i < n; i++){ z -= monsters[i].d; if (z <= 0){ cout << "NIE" << endl; return 0; } z += monsters[i].a; if (i != 0) sresult << " "; sresult << monsters[i].id; } cout << "TAK" << endl << sresult.str() << 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 | #include <iostream> #include <algorithm> #include <sstream> using namespace std; #define MONSTERS 100000 class monster{ public: int d, a, zysk, sign, id; bool operator<(const monster& right)const{ if (sign > right.sign)return true; if (sign < right.sign)return false; if (sign > 0) return d < right.d; return a > right.a; } }; monster monsters[MONSTERS]; int main(){ cin.sync_with_stdio(false); int n, z; cin >> n >> z; for (int i = 0; i < n; i++){ cin >> monsters[i].d >> monsters[i].a; monsters[i].zysk = monsters[i].a - monsters[i].d; if (monsters[i].zysk>0){ monsters[i].sign = 1; }else if (monsters[i].zysk<0){ monsters[i].sign = -1; } else { monsters[i].sign = 0; } monsters[i].id = i + 1; } sort(monsters,monsters+n); stringstream sresult; for (int i = 0; i < n; i++){ z -= monsters[i].d; if (z <= 0){ cout << "NIE" << endl; return 0; } z += monsters[i].a; if (i != 0) sresult << " "; sresult << monsters[i].id; } cout << "TAK" << endl << sresult.str() << endl; return 0; } |