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
#include <iostream>
#include <vector>

struct Tea
{
    int amountOfTea = 0;
    double startTemperature = 0;
    double requiredTemperature = 0;
};

double requiredAmountOfTea(Tea *&t1, Tea *&t2)
{
    int a = t1->amountOfTea;
    double r = t1->requiredTemperature;
    double ta = t1->startTemperature;
    double tb = t2->startTemperature;
    if (r - tb == 0)
    {
        return 0;
    }
    return ((a * ta) - (a * r)) / (r - tb);
}

int main()
{
    int t;
    std::cin >> t;

    for (int i = 0; i < t; i++)
    {
        int n;
        std::cin >> n;

        double sumOfStartTemperature = 0;
        double sumOfRequiredTemperature = 0;

        auto teaList = std::vector<Tea *>(static_cast<unsigned long>(n));
        for (int x = 0; x < n; x++)
        {
            Tea *pTea = new Tea{};
            std::cin >> pTea->amountOfTea;
            std::cin >> pTea->startTemperature;
            std::cin >> pTea->requiredTemperature;

            sumOfStartTemperature += pTea->amountOfTea * pTea->startTemperature;
            sumOfRequiredTemperature += pTea->amountOfTea * pTea->requiredTemperature;

            teaList[x] = pTea;
        }

        if (sumOfStartTemperature != sumOfRequiredTemperature)
        {
            std::cout << "NIE" << std::endl;
            continue;
        }
        bool isPossible = true;
        for (auto t1 : teaList)
        {
            bool currentPossible = false;
            for (auto t2 : teaList)
            {
                if (t1 == t2)
                {
                    continue;
                }
                double amountOfTea = requiredAmountOfTea(t1, t2);
                if (amountOfTea >= 0)
                {
                    currentPossible = true;
                }
            }
            if (!currentPossible)
            {
                isPossible = false;
            }
        }
        std::cout << (isPossible ? "TAK" : "NIE") << std::endl;
    }
}