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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include<iostream>
#include<fstream>
#include<vector>

using namespace std;

int main(){


    int n,m;
    cin>>n>>m;

    int tab1[1000000]={};
    int tab2[1000000]={};
    int starting[1000000]={},ending[1000000]={};

    int p,k,c;

    int pMin = 1000000;
    int MaxK = 0;

    for(int i=0;i<n;i++){
        cin>>p>>k>>c;
        for(int j=p;j<p+c;j++){
            tab1[j]++;
        }

        for(int j=p;j<k;j++){
            tab2[j]++;
        }

        starting[p]++;
        ending[k-1]++;


        if(p<pMin)
            pMin = p;
        if(k>MaxK)
            MaxK = k;
    }

    for(int i=1;i<1000000;i++){
        ending[i]+=ending[i-1];
    }

    int result[1000000] = {};
    int offset = 0;

    int granica = 0;
    int doDodania = 0,going = 0;

    for(int i=pMin;i<MaxK;i++){
        granica = tab2[i]>m ? m:tab2[i];

        if(granica == 0 && offset >0)
            break;


        if(going == 0 && offset>0){
            break;
        }

        going+=starting[i];


        if(tab1[i] == granica){
            result[i] = tab1[i];
        }
        else if(tab1[i] >granica) {
            offset+=tab1[i]-granica;
            result[i] = granica;
        }
        else{
            result[i] = tab1[i];
            granica -= tab1[i];
            doDodania = offset>granica ? granica:offset;
            offset-=doDodania;
            result[i]+=doDodania;
        }

        if(i>0){
            going-=(ending[i]-ending[i-1]);
        }

    }

    if(offset>0){
        cout<<"NIE"<<endl;
    }
    else {
        cout<<"TAK"<<endl;
    }




}