#include <cstdio> #include <algorithm> using namespace std; const int MAX = (int)10e6 + 1; int ADD[MAX]; int a_prt; int SUBB[MAX]; int b_prt; int Win[MAX]; bool cmp_more(int a, int b) { return Win[a-1]>Win[b-1] ? true : false; } bool cmp_less(int a, int b) { return Win[a-1]<Win[b-1] ? true : false; } int main() { int N; long long Z; scanf("%d %lld", &N, &Z); for(int i = 1; i<=N; i++) { int A, B; scanf("%d %d", &A, &B); B -= A; Win[i-1] = B; if(B>=0) ADD[a_prt++] = i; else SUBB[b_prt++] = i; Z += static_cast<long long>(B); } if(Z>0) { printf("TAK\n"); sort(ADD, ADD + a_prt, cmp_more); sort(SUBB, SUBB + b_prt, cmp_less); for(int i = 0; i<a_prt; i++) { printf("%d ", ADD[i]); } for(int i = 0; i<b_prt; i++) { printf("%d ", SUBB[i]); } } else printf("NIE\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 56 57 58 59 60 61 | #include <cstdio> #include <algorithm> using namespace std; const int MAX = (int)10e6 + 1; int ADD[MAX]; int a_prt; int SUBB[MAX]; int b_prt; int Win[MAX]; bool cmp_more(int a, int b) { return Win[a-1]>Win[b-1] ? true : false; } bool cmp_less(int a, int b) { return Win[a-1]<Win[b-1] ? true : false; } int main() { int N; long long Z; scanf("%d %lld", &N, &Z); for(int i = 1; i<=N; i++) { int A, B; scanf("%d %d", &A, &B); B -= A; Win[i-1] = B; if(B>=0) ADD[a_prt++] = i; else SUBB[b_prt++] = i; Z += static_cast<long long>(B); } if(Z>0) { printf("TAK\n"); sort(ADD, ADD + a_prt, cmp_more); sort(SUBB, SUBB + b_prt, cmp_less); for(int i = 0; i<a_prt; i++) { printf("%d ", ADD[i]); } for(int i = 0; i<b_prt; i++) { printf("%d ", SUBB[i]); } } else printf("NIE\n"); return 0; } |