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
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair < int, int > PII;

const int N = 1e6;

int n, m;
vector < pair < PII, int > > e;
vector < int > p, k;

int blo[N + 7];

inline int count(PII a, PII b)
{
    return max(min(a.second, b.second) - max(a.first, b.first), 0);
}

int main()
{
    scanf("%d%d", &n, &m);
    for(int i = 0; i < n; i++)
    {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        e.push_back({{a, b}, c});
        p.push_back(a), k.push_back(b);
    }

    for(auto a: p)
    {
        for(auto b: k)
        {
            if(a >= b) continue;
            int s = 0;
            for(auto x: e)
                s += max(x.second + count(make_pair(a, b), x.first) - (x.first.second - x.first.first), 0);
            if(s > m * (b - a))
            {
                puts("NIE");
                return 0;
            }
        }
    }
    puts("TAK");
    return 0;
}