#include <iostream> using namespace std; int main() { int T, N, a, b, l; cin >> T; for (int t = 0; t < T; t++) { cin >> N; long long totalASum = 0; long long totalBSum = 0; long long maxValue = 0; bool isMaxFinal = false; long long maxL = 0; long long minValue = 10000000; bool isMinFinal = false; long long minL = 0; for (int n = 0; n < N; n++) { cin >> l >> a >> b; totalASum += l * a; totalBSum += l * b; if (a > maxValue) { maxValue = a; isMaxFinal = false; maxL = l; } if (a < minValue) { minValue = a; isMinFinal = false; minL = l; } if (a == maxValue && l >= maxL) { maxValue = a; isMaxFinal = false; maxL = l; } if (a == minValue && l >= minL) { minValue = a; isMinFinal = false; minL = l; } if (b > maxValue) { maxValue = b; isMaxFinal = true; maxL = l; } if (b < minValue) { minValue = b; isMinFinal = true; minL = l; } if (b == maxValue && l > maxL) { maxValue = b; isMaxFinal = true; maxL = l; } if (b == minValue && l > minL) { minValue = a; isMinFinal = true; minL = l; } } if (totalASum == totalBSum && !isMaxFinal && !isMinFinal) { cout << "TAK" << endl; } else { cout << "NIE" << endl; } } return 0; }
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 80 81 82 83 84 85 86 87 | #include <iostream> using namespace std; int main() { int T, N, a, b, l; cin >> T; for (int t = 0; t < T; t++) { cin >> N; long long totalASum = 0; long long totalBSum = 0; long long maxValue = 0; bool isMaxFinal = false; long long maxL = 0; long long minValue = 10000000; bool isMinFinal = false; long long minL = 0; for (int n = 0; n < N; n++) { cin >> l >> a >> b; totalASum += l * a; totalBSum += l * b; if (a > maxValue) { maxValue = a; isMaxFinal = false; maxL = l; } if (a < minValue) { minValue = a; isMinFinal = false; minL = l; } if (a == maxValue && l >= maxL) { maxValue = a; isMaxFinal = false; maxL = l; } if (a == minValue && l >= minL) { minValue = a; isMinFinal = false; minL = l; } if (b > maxValue) { maxValue = b; isMaxFinal = true; maxL = l; } if (b < minValue) { minValue = b; isMinFinal = true; minL = l; } if (b == maxValue && l > maxL) { maxValue = b; isMaxFinal = true; maxL = l; } if (b == minValue && l > minL) { minValue = a; isMinFinal = true; minL = l; } } if (totalASum == totalBSum && !isMaxFinal && !isMinFinal) { cout << "TAK" << endl; } else { cout << "NIE" << endl; } } return 0; } |