#include <cstdio> #include <algorithm> using namespace std; pair<int, int> t[500001]; long long pref[500001]; char ret[500001]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &t[i].first); t[i].second = i; } sort(t, t + n); if (t[0].first == t[n - 1].first) { for (int i = 0; i < n; i++) { ret[i] = 'N'; } printf("%s\n", ret); return 0; } pref[0] = t[0].first; for (int i = 1; i < n; i++) { pref[i] = pref[i - 1] + t[i].first; } int idx = n - 1; int m = t[n - 1].first; for (int i = n - 1; i >= 0; i--) { if (m == t[i].first) { idx = i; } else if (t[i].first == t[0].first) { idx = i; break; } else { if (pref[i] <= t[i + 1].first) { idx = i; break; } } } for (int i = 0; i < n; i++) { if (i <= idx) { ret[t[i].second] = 'N'; } else { ret[t[i].second] = 'T'; } } printf("%s\n", ret); 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 75 76 77 78 79 80 81 | #include <cstdio> #include <algorithm> using namespace std; pair<int, int> t[500001]; long long pref[500001]; char ret[500001]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &t[i].first); t[i].second = i; } sort(t, t + n); if (t[0].first == t[n - 1].first) { for (int i = 0; i < n; i++) { ret[i] = 'N'; } printf("%s\n", ret); return 0; } pref[0] = t[0].first; for (int i = 1; i < n; i++) { pref[i] = pref[i - 1] + t[i].first; } int idx = n - 1; int m = t[n - 1].first; for (int i = n - 1; i >= 0; i--) { if (m == t[i].first) { idx = i; } else if (t[i].first == t[0].first) { idx = i; break; } else { if (pref[i] <= t[i + 1].first) { idx = i; break; } } } for (int i = 0; i < n; i++) { if (i <= idx) { ret[t[i].second] = 'N'; } else { ret[t[i].second] = 'T'; } } printf("%s\n", ret); return 0; } |