#include <cstdio> #include <vector> #include <algorithm> #include <utility> #include <string> int main() { int n; scanf("%d", &n); int t; unsigned long long sum = 0ULL; std::vector<std::pair<int, int>> s; s.reserve(n); for (int i = 0; i < n; ++i) { scanf("%d", &t); s.emplace_back(t, i); sum += t; } std::sort(s.begin(), s.end(), std::greater<std::pair<int, int>>()); std::string result = std::string(n, 'N'); unsigned long long minw = s[0].first; for (auto p : s) { if (sum > minw && p.first > s.back().first) { result[p.second] = 'T'; minw = p.first; } sum -= p.first; } printf("%s\n", result.c_str()); 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 | #include <cstdio> #include <vector> #include <algorithm> #include <utility> #include <string> int main() { int n; scanf("%d", &n); int t; unsigned long long sum = 0ULL; std::vector<std::pair<int, int>> s; s.reserve(n); for (int i = 0; i < n; ++i) { scanf("%d", &t); s.emplace_back(t, i); sum += t; } std::sort(s.begin(), s.end(), std::greater<std::pair<int, int>>()); std::string result = std::string(n, 'N'); unsigned long long minw = s[0].first; for (auto p : s) { if (sum > minw && p.first > s.back().first) { result[p.second] = 'T'; minw = p.first; } sum -= p.first; } printf("%s\n", result.c_str()); return 0; } |