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
62
63
64
65
66
67
68
69
70
71
72
73
#include <cstdio>
#include <algorithm>
#include <vector>

struct monster
{
    int id;
    int d;
    int a;
};

bool cmp1 (monster a, monster b)
{
    return a.d < b.d;
}

bool cmp2 (monster a, monster b)
{
    return a.a > b.a;
}

int main ()
{
    std::vector <monster> pos;
    std::vector <monster> neg;
    int n;
    long long z;
    monster tmp;
    scanf ("%d %lli", &n, &z);
    int i;
    for (i = 1; i <= n; ++ i)
    {
        scanf ("%d %d", &tmp.d, &tmp.a);
        tmp.id = i;
        if (tmp.a - tmp.d >= 0)
            pos.push_back (tmp);
        else
            neg.push_back (tmp);
    }
    std::sort (pos.begin (), pos.end (), cmp1);
    for (i = 0; i < pos.size (); ++ i)
    {
        z -= pos [i].d;
        if (z <= 0)
        {
            printf ("NIE\n");
            return 0;
        }
        z += pos [i].a;
    }
    std::sort (neg.begin (), neg.end (), cmp2);
    for (i = 0; i < neg.size (); ++ i)
    {
        z -= neg [i].d;
        if (z <= 0)
        {
            printf ("NIE\n");
            return 0;
        }
        z += neg [i].a;
    }
    printf ("TAK\n");
    for (i = 0; i < pos.size (); ++ i)
    {
        printf ("%d ", pos [i].id);
    }
    for (i = 0; i < neg.size (); ++ i)
    {
        printf ("%d ", neg [i].id);
    }
    printf ("\n");
    return 0;
}