#include <iostream> using namespace std; int main() { unsigned long long t; cin >> t; for (unsigned long long i = 0; i < t; ++i) { unsigned long long n; cin >> n; unsigned long long max_a = 0, min_a = 1000001, max_b = 0, min_b = 1000001; unsigned long long sum_a = 0, sum_b = 0; for (unsigned long long j = 0; j < n; ++j) { unsigned long long l; cin >> l; unsigned long long a; cin >> a; if (a > max_a) max_a = a; if (a < min_a) min_a = a; sum_a += l * a; unsigned long long b; cin >> b; if (b > max_b) max_b = b; if (b < min_b) min_b = b; sum_b += l * b; } if (min_b < min_a || max_b>max_a) { cout << "NIE" << endl; continue; } if (sum_a == sum_b) 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 | #include <iostream> using namespace std; int main() { unsigned long long t; cin >> t; for (unsigned long long i = 0; i < t; ++i) { unsigned long long n; cin >> n; unsigned long long max_a = 0, min_a = 1000001, max_b = 0, min_b = 1000001; unsigned long long sum_a = 0, sum_b = 0; for (unsigned long long j = 0; j < n; ++j) { unsigned long long l; cin >> l; unsigned long long a; cin >> a; if (a > max_a) max_a = a; if (a < min_a) min_a = a; sum_a += l * a; unsigned long long b; cin >> b; if (b > max_b) max_b = b; if (b < min_b) min_b = b; sum_b += l * b; } if (min_b < min_a || max_b>max_a) { cout << "NIE" << endl; continue; } if (sum_a == sum_b) cout << "TAK" << endl; else cout << "NIE" << endl; } return 0; } |