import sys def is_valid_count(n, a): total_moves = sum(a) max_a = max(a) if total_moves % 2 != 0: return "NIE" if max_a > total_moves // 2: return "NIE" if n == 1: return "TAK" if a[0] > 0 else "NIE" return "TAK" def main(): data = sys.stdin.read().split() index = 0 t = int(data[index]) index += 1 results = [] for _ in range(t): n = int(data[index]) index += 1 a = list(map(int, data[index:index + n])) index += n results.append(is_valid_count(n, a)) sys.stdout.write("\n".join(results) + "\n") if __name__ == "__main__": main()
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 | import sys def is_valid_count(n, a): total_moves = sum(a) max_a = max(a) if total_moves % 2 != 0: return "NIE" if max_a > total_moves // 2: return "NIE" if n == 1: return "TAK" if a[0] > 0 else "NIE" return "TAK" def main(): data = sys.stdin.read().split() index = 0 t = int(data[index]) index += 1 results = [] for _ in range(t): n = int(data[index]) index += 1 a = list(map(int, data[index:index + n])) index += n results.append(is_valid_count(n, a)) sys.stdout.write("\n".join(results) + "\n") if __name__ == "__main__": main() |