#include <array> #include <algorithm> #include <functional> #include <iostream> std::array <uint64_t, 500000> raw; std::array <uint64_t, 500000> sorted; int main() { int n; std::cin >> n; for (int i = 0; i < n; ++i) { uint64_t a; std::cin >> a; raw[i] = a; sorted[i] = a; } std::sort(sorted.begin(), sorted.begin() + n, std::less <uint64_t> ()); uint64_t prev = sorted[0]; uint64_t lowest_failer = prev; int i = 0; while (sorted[i] == prev && i < n) ++i; uint64_t total = i * prev; for (; i < n; ++i) { uint64_t a = sorted[i]; if (a >= total) lowest_failer = prev; total += a; prev = a; } for (int i = 0; i < n; ++i) { if (raw[i] <= lowest_failer) std::cout << 'N'; else std::cout << 'T'; } 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 | #include <array> #include <algorithm> #include <functional> #include <iostream> std::array <uint64_t, 500000> raw; std::array <uint64_t, 500000> sorted; int main() { int n; std::cin >> n; for (int i = 0; i < n; ++i) { uint64_t a; std::cin >> a; raw[i] = a; sorted[i] = a; } std::sort(sorted.begin(), sorted.begin() + n, std::less <uint64_t> ()); uint64_t prev = sorted[0]; uint64_t lowest_failer = prev; int i = 0; while (sorted[i] == prev && i < n) ++i; uint64_t total = i * prev; for (; i < n; ++i) { uint64_t a = sorted[i]; if (a >= total) lowest_failer = prev; total += a; prev = a; } for (int i = 0; i < n; ++i) { if (raw[i] <= lowest_failer) std::cout << 'N'; else std::cout << 'T'; } std::cout << std::endl; return 0; } |