#include <iostream> #include <vector> #include <numeric> #include <algorithm> using namespace std; bool is_valid_counting_game(const vector<int>& a) { long long total_steps = accumulate(a.begin(), a.end(), 0LL); int max_value = *max_element(a.begin(), a.end()); // Warunek konieczny: suma wskazań musi być parzysta if (total_steps % 2 != 0) return false; // Warunek konieczny: maksymalna wartość nie może przekraczać połowy sumy wskazań if (max_value > total_steps / 2) return false; return true; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } cout << (is_valid_counting_game(a) ? "TAK" : "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 | #include <iostream> #include <vector> #include <numeric> #include <algorithm> using namespace std; bool is_valid_counting_game(const vector<int>& a) { long long total_steps = accumulate(a.begin(), a.end(), 0LL); int max_value = *max_element(a.begin(), a.end()); // Warunek konieczny: suma wskazań musi być parzysta if (total_steps % 2 != 0) return false; // Warunek konieczny: maksymalna wartość nie może przekraczać połowy sumy wskazań if (max_value > total_steps / 2) return false; return true; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } cout << (is_valid_counting_game(a) ? "TAK" : "NIE") << '\n'; } return 0; } |