#include <cstdio> #include <algorithm> using namespace std; pair<int,int> monsters[100001]; int result[100000]; int n, d, a; long long z; struct monstercmp { bool operator()(int a, int b) { if (monsters[a].second - monsters[a].first >= 0) { if (monsters[b].second - monsters[b].first >= 0) { return monsters[a].first < monsters[b].first; } else return true; } else { if (monsters[b].second - monsters[b].first >= 0) { return false; } else { return monsters[a].second > monsters[b].second; } } } }; int main() { scanf("%d%lld",&n,&z); for (int i = 0; i < n; i++) { scanf("%d%d",&monsters[i+1].first,&monsters[i+1].second); result[i] = i+1; } sort(result, result + n, monstercmp()); for (int i = 0; i < n; i++) { z -= monsters[result[i]].first; if (z <= 0) { printf("NIE\n"); return 0; } z += monsters[result[i]].second; } printf("TAK\n"); for (int i = 0; i < n; i++) { printf("%d ", result[i]); } printf("\n"); 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 <cstdio> #include <algorithm> using namespace std; pair<int,int> monsters[100001]; int result[100000]; int n, d, a; long long z; struct monstercmp { bool operator()(int a, int b) { if (monsters[a].second - monsters[a].first >= 0) { if (monsters[b].second - monsters[b].first >= 0) { return monsters[a].first < monsters[b].first; } else return true; } else { if (monsters[b].second - monsters[b].first >= 0) { return false; } else { return monsters[a].second > monsters[b].second; } } } }; int main() { scanf("%d%lld",&n,&z); for (int i = 0; i < n; i++) { scanf("%d%d",&monsters[i+1].first,&monsters[i+1].second); result[i] = i+1; } sort(result, result + n, monstercmp()); for (int i = 0; i < n; i++) { z -= monsters[result[i]].first; if (z <= 0) { printf("NIE\n"); return 0; } z += monsters[result[i]].second; } printf("TAK\n"); for (int i = 0; i < n; i++) { printf("%d ", result[i]); } printf("\n"); return 0; } |