#include <iostream> using namespace std; typedef long long ll; const ll INF = 1000000000000000000; int main() { ios_base::sync_with_stdio(0); int t; cin >> t; for (int i = 0; i < t; ++i) { ll s1 = 0, s2 = 0, m1 = INF, M1 = -INF, m2 = INF, M2 = -INF; int n; cin >> n; for (int j = 0; j < n; ++j) { ll l, a, b; cin >> l >> a >> b; s1 += l * a; s2 += l * b; m1 = min(m1, a); M1 = max(M1, a); m2 = min(m2, b); M2 = max(M2, b); } if (s1 == s2 && m2 >= m1 && m2 <= M1 && M2 >= m1 && M2 <= M1) cout << "TAK"; else cout << "NIE"; cout << 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 | #include <iostream> using namespace std; typedef long long ll; const ll INF = 1000000000000000000; int main() { ios_base::sync_with_stdio(0); int t; cin >> t; for (int i = 0; i < t; ++i) { ll s1 = 0, s2 = 0, m1 = INF, M1 = -INF, m2 = INF, M2 = -INF; int n; cin >> n; for (int j = 0; j < n; ++j) { ll l, a, b; cin >> l >> a >> b; s1 += l * a; s2 += l * b; m1 = min(m1, a); M1 = max(M1, a); m2 = min(m2, b); M2 = max(M2, b); } if (s1 == s2 && m2 >= m1 && m2 <= M1 && M2 >= m1 && M2 <= M1) cout << "TAK"; else cout << "NIE"; cout << endl; } return 0; } |