/* 5 2 2 1 4 2 5 2 2 1 4 3 1 5 4 2 1 5 7 1 7 5 2 1 4 1 1 2 5 3 2 6 4 1 2 3 3 4 5 */ #include <iostream> #include <vector> #include <algorithm> #include <string> #include <utility> using namespace std; typedef long long ll; string solve(vector<ll> &l, vector<ll> &a, vector<ll> &b, ll n) { auto it_max_a = max_element(std::begin(a), std::end(a)); auto it_min_a = min_element(std::begin(a), std::end(a)); auto it_max_b = max_element(std::begin(b), std::end(b)); auto it_min_b = min_element(std::begin(b), std::end(b)); if (*it_max_b > *it_max_a || *it_min_b < *it_min_a) return "NIE"; ll suma = 0; ll sumb = 0; for (ll i = 0; i < n; i++) { suma += l[i]*a[i]; sumb += l[i]*b[i]; } return suma == sumb ? "TAK" : "NIE"; } int main() { ios_base::sync_with_stdio(false); ll num_of_tests; cin >> num_of_tests; for (ll i = 0; i < num_of_tests; i++) { ll n; cin >> n; vector<ll> l; vector<ll> a; vector<ll> b; ll tl, ta, tb;; for (int j = 0; j < n; j++) { cin >> tl >> ta >> tb; l.push_back(tl); a.push_back(ta); b.push_back(tb); } cout << solve(l,a,b,n) << 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 | /* 5 2 2 1 4 2 5 2 2 1 4 3 1 5 4 2 1 5 7 1 7 5 2 1 4 1 1 2 5 3 2 6 4 1 2 3 3 4 5 */ #include <iostream> #include <vector> #include <algorithm> #include <string> #include <utility> using namespace std; typedef long long ll; string solve(vector<ll> &l, vector<ll> &a, vector<ll> &b, ll n) { auto it_max_a = max_element(std::begin(a), std::end(a)); auto it_min_a = min_element(std::begin(a), std::end(a)); auto it_max_b = max_element(std::begin(b), std::end(b)); auto it_min_b = min_element(std::begin(b), std::end(b)); if (*it_max_b > *it_max_a || *it_min_b < *it_min_a) return "NIE"; ll suma = 0; ll sumb = 0; for (ll i = 0; i < n; i++) { suma += l[i]*a[i]; sumb += l[i]*b[i]; } return suma == sumb ? "TAK" : "NIE"; } int main() { ios_base::sync_with_stdio(false); ll num_of_tests; cin >> num_of_tests; for (ll i = 0; i < num_of_tests; i++) { ll n; cin >> n; vector<ll> l; vector<ll> a; vector<ll> b; ll tl, ta, tb;; for (int j = 0; j < n; j++) { cin >> tl >> ta >> tb; l.push_back(tl); a.push_back(ta); b.push_back(tb); } cout << solve(l,a,b,n) << endl;; } return 0; } |