#include <iostream> #include <vector> #include <algorithm> using namespace std; bool checkSequence(const vector<int>& a) { int n = a.size(); if (n == 1) return true; for (int i = 1; i < n - 1; ++i) { if (a[i] < a[i - 1] + a[i + 1]) continue; return false; } return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n); for (int& x : a) cin >> x; if (n == 1) { cout << "TAK\n"; continue; } if (n == 2) { if (a[0] == a[1]) cout << "TAK\n"; else cout << "NIE\n"; continue; } if (checkSequence(a)) cout << "TAK\n"; else cout << "NIE\n"; } 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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; bool checkSequence(const vector<int>& a) { int n = a.size(); if (n == 1) return true; for (int i = 1; i < n - 1; ++i) { if (a[i] < a[i - 1] + a[i + 1]) continue; return false; } return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n); for (int& x : a) cin >> x; if (n == 1) { cout << "TAK\n"; continue; } if (n == 2) { if (a[0] == a[1]) cout << "TAK\n"; else cout << "NIE\n"; continue; } if (checkSequence(a)) cout << "TAK\n"; else cout << "NIE\n"; } return 0; } |