#include <bits/stdc++.h> struct Catfish { int64_t size; size_t position; char possible_king; }; bool cmp1(const Catfish &c1, const Catfish &c2) { return c1.size < c2.size; } bool cmp2(const Catfish &c1, const Catfish &c2) { return c1.position < c2.position; } int32_t main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); unsigned int catfish_number; std::cin >> catfish_number; std::vector <Catfish> catfish(catfish_number); int64_t first_catfish; std::cin >> first_catfish; catfish[0] = {first_catfish, 0, 'N'}; bool different = false; int64_t smallest = LLONG_MAX; smallest = std::min(smallest, first_catfish); for (size_t i = 1; i < catfish_number; ++i) { int64_t current_catfish; std::cin >> current_catfish; catfish[i] = {current_catfish, i, 'N'}; if (current_catfish != first_catfish) different = true; smallest = std::min(smallest, current_catfish); } if (!different) { for (auto i : catfish) std::cout << i.possible_king; std::cout << '\n'; } else { std::sort(catfish.begin(), catfish.end(), cmp1); std::vector <int64_t> prefix_sum(catfish_number); prefix_sum[0] = catfish[0].size; for (size_t i = 1; i < catfish_number; ++i) prefix_sum[i] = prefix_sum[i - 1] + catfish[i].size; int j = catfish_number - 1; while (catfish[j].size == catfish[catfish_number - 1].size && j) catfish[j--].possible_king = 'T'; for (int i = catfish_number - 2; i > 0; --i) { if (prefix_sum[i] > catfish[i + 1].size && catfish[i + 1].possible_king == 'T' && catfish[i].size != smallest) catfish[i].possible_king = 'T'; } std::sort(catfish.begin(), catfish.end(), cmp2); for (Catfish c : catfish) std::cout << c.possible_king; std::cout << std::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 | #include <bits/stdc++.h> struct Catfish { int64_t size; size_t position; char possible_king; }; bool cmp1(const Catfish &c1, const Catfish &c2) { return c1.size < c2.size; } bool cmp2(const Catfish &c1, const Catfish &c2) { return c1.position < c2.position; } int32_t main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); unsigned int catfish_number; std::cin >> catfish_number; std::vector <Catfish> catfish(catfish_number); int64_t first_catfish; std::cin >> first_catfish; catfish[0] = {first_catfish, 0, 'N'}; bool different = false; int64_t smallest = LLONG_MAX; smallest = std::min(smallest, first_catfish); for (size_t i = 1; i < catfish_number; ++i) { int64_t current_catfish; std::cin >> current_catfish; catfish[i] = {current_catfish, i, 'N'}; if (current_catfish != first_catfish) different = true; smallest = std::min(smallest, current_catfish); } if (!different) { for (auto i : catfish) std::cout << i.possible_king; std::cout << '\n'; } else { std::sort(catfish.begin(), catfish.end(), cmp1); std::vector <int64_t> prefix_sum(catfish_number); prefix_sum[0] = catfish[0].size; for (size_t i = 1; i < catfish_number; ++i) prefix_sum[i] = prefix_sum[i - 1] + catfish[i].size; int j = catfish_number - 1; while (catfish[j].size == catfish[catfish_number - 1].size && j) catfish[j--].possible_king = 'T'; for (int i = catfish_number - 2; i > 0; --i) { if (prefix_sum[i] > catfish[i + 1].size && catfish[i + 1].possible_king == 'T' && catfish[i].size != smallest) catfish[i].possible_king = 'T'; } std::sort(catfish.begin(), catfish.end(), cmp2); for (Catfish c : catfish) std::cout << c.possible_king; std::cout << std::endl; } return 0; } |