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
#include <cstdio>
#include <algorithm>

void solve_case(unsigned entries) {
	unsigned long long current_sum = 0;
	unsigned long long expected_sum = 0;
	unsigned long long current_min = std::numeric_limits<unsigned long long>::max();
	unsigned long long expected_min = std::numeric_limits<unsigned long long>::max();
	unsigned long long current_max = 0;
	unsigned long long expected_max = 0;
	for (unsigned e = 0; e < entries; ++e) {
		unsigned long long liters, current, expected;
		scanf("%llu %llu %llu\n", &liters, &current, &expected);
		current_sum += (unsigned long long)liters * current;
		expected_sum += (unsigned long long)liters * expected;
		current_min = std::min(current_min, current);
		expected_min = std::min(expected_min, expected);
		current_max = std::max(current_max, current);
		expected_max = std::max(expected_max, expected);
	}
	//printf("s1 %llu s2 %llu, current %llu-%llu, expected %llu-%llu", current_sum, expected_sum, current_min, current_max, expected_min, expected_max);
	if (current_sum != expected_sum) {
		printf("NIE\n");
		return;
	}
	printf((expected_min >= current_min && expected_max <= current_max) ? "TAK\n" : "NIE\n");
}

int main(int argc, char* argv[]) {
	unsigned cases;
	unsigned entries;
	scanf("%u\n", &cases);
	for (unsigned c = 0; c < cases; ++c) {
		scanf("%u\n", &entries);
		solve_case(entries);
	}
}