#include <bits/stdc++.h> #define REP(i,n) for (int _n=(n), i=0;i<_n;++i) #define FOR(i,a,b) for (int i=(a),_b=(b);i<=_b;++i) #define FORD(i,a,b) for (int i=(a),_b=(b);i>=_b;--i) #define TRACE(x) std::cerr << "TRACE(" #x ")" << std::endl; #define DEBUG(x) std::cerr << #x << " = " << (x) << std::endl; void init_io() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); } std::vector<int> masses; std::vector<int> sorted_masses; void read_input() { int n; std::cin >> n; masses.reserve(n); REP(i,n) { int mass; std::cin >> mass; masses.push_back(mass); } } class King {}; bool is_less_than_king(const int starting_mass, King) { bool seen_myself = false; std::int64_t current = starting_mass; for (const int m : sorted_masses) { if (m == starting_mass && !seen_myself) { seen_myself = true; continue; } if (current <= m) return true; current += m; } return false; } int find_min_mass() { sorted_masses = masses; std::sort(sorted_masses.begin(), sorted_masses.end()); const auto it = std::lower_bound(sorted_masses.begin(), sorted_masses.end(), King{}, is_less_than_king); if (it == sorted_masses.end()) return sorted_masses.back() + 1; return *it; } void print_output(const int min_mass) { for (const int mass: masses) { std::cout << (mass >= min_mass ? 'T' : 'N'); } std::cout << '\n'; } int main() { init_io(); read_input(); const int min_mass = find_min_mass(); print_output(min_mass); }
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 | #include <bits/stdc++.h> #define REP(i,n) for (int _n=(n), i=0;i<_n;++i) #define FOR(i,a,b) for (int i=(a),_b=(b);i<=_b;++i) #define FORD(i,a,b) for (int i=(a),_b=(b);i>=_b;--i) #define TRACE(x) std::cerr << "TRACE(" #x ")" << std::endl; #define DEBUG(x) std::cerr << #x << " = " << (x) << std::endl; void init_io() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); } std::vector<int> masses; std::vector<int> sorted_masses; void read_input() { int n; std::cin >> n; masses.reserve(n); REP(i,n) { int mass; std::cin >> mass; masses.push_back(mass); } } class King {}; bool is_less_than_king(const int starting_mass, King) { bool seen_myself = false; std::int64_t current = starting_mass; for (const int m : sorted_masses) { if (m == starting_mass && !seen_myself) { seen_myself = true; continue; } if (current <= m) return true; current += m; } return false; } int find_min_mass() { sorted_masses = masses; std::sort(sorted_masses.begin(), sorted_masses.end()); const auto it = std::lower_bound(sorted_masses.begin(), sorted_masses.end(), King{}, is_less_than_king); if (it == sorted_masses.end()) return sorted_masses.back() + 1; return *it; } void print_output(const int min_mass) { for (const int mass: masses) { std::cout << (mass >= min_mass ? 'T' : 'N'); } std::cout << '\n'; } int main() { init_io(); read_input(); const int min_mass = find_min_mass(); print_output(min_mass); } |