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
//Pawel Kura, zadanie Szeregowanie zadan

#include <bits/stdc++.h>

using namespace std;

int n,m;

struct task {
    int from, to, dur;
    task(int from=-1, int to=-1, int dur=-1):from(from), to(to), dur(dur) {}
};
const int MAXN = 100;

vector<task> v;
int maxt;
int lef[MAXN], done[MAXN];

int main() {
    cin >> n >> m;
    v.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i].from >> v[i].to >> v[i].dur;
        v[i].to--;

        maxt = max(maxt, v[i].to);

        if (v[i].from + v[i].dur - 1 > v[i].to) {
            cout << "NIE\n";
            return 0;
        }
    }

    for (int i = 0; i <= maxt; i++) {
        vector<pair<int,int>> w;
        for (int j = 0; j < n; j++) {
            auto t = v[j];
            if (t.from == i) {
                lef[j] = t.dur;
            }
            if (t.from <= i && i <= t.to && lef[j] > 0) {
                int x = t.to - i + 1 - lef[j];
                w.push_back({x, j});
            }
        }

        sort(begin(w), end(w));

        int k = min((int)w.size(), m);
        for (int j = 0; j < k; j++) {
            int z = w[j].second;
            lef[z]--;

            if (lef[z] == 0) done[z] = 1;
        }
    }

    for (int i = 0; i < n; i++) {
        if (!done[i]) {
            cout << "NIE\n";
            return 0;
        }
    }

    cout << "TAK\n";
    return 0;
}