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
#include <stdio.h>
#include <stdlib.h>
#define N 1000000
int n,s;
int dec[N], inc[N];
int in[N],cn,cp;
int cmpp(int *a, int *b) {
	return dec[*a] - dec[*b];
}
int cmpn(int *a, int *b) {
	return inc[*b] - inc[*a];
}
int main() {
	int i, r = 1;
	long long sum;
	scanf("%d%d",&n,&s);
	sum = s;
	for (i = 0; i < n; i++) {
		scanf("%d%d",dec+i,inc+i);
		sum += inc[i] - dec[i];
		if (dec[i]<=inc[i]) in[cp++] = i;
		else in[n-++cn] = i;
	}
	if (sum <= 0) {
		puts("NIE");
		return 0;
	}
	qsort(in, cp, sizeof(*in), cmpp);
	qsort(in+cp, cn, sizeof(*in), cmpn);
	sum = s;
	for (i = 0; i < n; i++) r &= sum > dec[in[i]], sum += inc[in[i]] - dec[in[i]];
	puts(r?"TAK":"NIE");
	if (!r) return 0;
	for (i = 0; i < n - 1; i++) printf("%d ",in[i]+1);
	printf("%d\n", in[i]+1);
	return 0;
}