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
#include <stdio.h>

int main() {
    int n,m;
    scanf("%i %i", &n, &m);
    int p[n],k[n],c[n];
    int maxk = 0;
    for (int i=0; i<n; ++i) {
        scanf("%i %i %i", &p[i], &k[i], &c[i]);   
        if (k[i]>maxk) maxk = k[i];
    }

    int used[maxk];
    for (int i=0; i<maxk; ++i) {
        used[i] = 0;
    }

    for (int i=0; i<maxk; ++i) {
        for (int j=0; j<n; ++j) {
            if (i>=k[j]-c[j] && i<k[j]) {

                bool found=false;
                for (int x=p[j]; x<=i; ++x) {
                    if (used[x] < m) {
                        used[x]++;
                        found=true;                    
                    }
                }
                if (!found) {
                    //printf("i=%i j=%i\n", i,j );
                    printf("NIE\n");    
                    return 0;            
                } 

            }
        }
    }

    printf("TAK\n");
    return 0;
}