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
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
const int infinity = 1000000000;

struct Noob{
	int l,a,b;
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		vector<Noob>NoobTeam(n);
		for(Noob &x : NoobTeam)
			cin >> x.l >> x.a >> x.b;
		
		bool testFailed=false;
		
		//Heura A = ograniczenia dolne i górne
		int mn=infinity, mx=-infinity;
		for(const Noob &x : NoobTeam){
			mn=min(mn, x.a);
			mx=max(mx, x.a);
		}
		for(const Noob &x : NoobTeam)
			if(x.b<mn || x.b>mx)
				testFailed=true;
		
		//Heura B = bilans energi
		long long energy=0;
		for(const Noob &x : NoobTeam)
			energy += x.l*(x.a-x.b);
		if(energy!=0)
			testFailed=true;
		
		//Heura C = entropia
		double deltaEntropy=0.0;
		for(const Noob &x : NoobTeam)
			deltaEntropy += (double)x.l*log(x.b)-log(x.a);
		if(deltaEntropy + 1e-6 < 0.0)
			testFailed=true;
		
		cout << (testFailed?"NIE\n":"TAK\n");
	}
	
	return 0;
}