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
74
75
76
77
78
79
80
81
82
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

typedef pair<int, int> PII;

const int MAX_N = 1e2 + 9;

pair<PII, int> tab[MAX_N];
PII active[MAX_N];

int n, m;

bool cmp(PII a, PII b)
{
    if(a.st < b.st)
        return true;
    else if(a.st > b.st)
        return false;
    else
        return a.nd > b.nd;
}

int main()
{
    scanf("%d %d", &n, &m);

    int endTime = 0;

    for(int i = 0; i < n; ++i)
    {
        scanf("%d %d %d", &tab[i].st.st, &tab[i].st.nd, &tab[i].nd);

        endTime = max(endTime, tab[i].st.nd);
    }

    sort(tab, tab + n);

    int ind = 0;
    int zeroed = 0;

    for(int t = 0; t <= endTime; ++t)
    {
        while(ind < n && tab[ind].st.st == t)
        {
            active[ind] = PII(tab[ind].st.nd - tab[ind].st.st - tab[ind].nd, tab[ind].nd);
            ++ind;
        }

        sort(active + zeroed, active + ind, cmp);

        int indend = m + zeroed;

        for(int i = zeroed; i < min(ind, indend); ++i)
        {
            --active[i].nd;

            if(active[i].nd == 0)
            {
                swap(active[i], active[zeroed]);
                ++zeroed;
            }
        }

        for(int i = indend; i < ind; ++i)
        {
            --active[i].st;

            if(active[i].st < 0)
            {
                printf("NIE\n");
                return 0;
            }
        }
    }

    printf("TAK\n");

    return 0;
}