#include <bits/stdc++.h> using namespace std; const int N = 500'007; int n; bool ans[N]; long long pref[N]; pair <int, int> in[N]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", &in[i].first); in[i].second = i; } sort(in + 1, in + n + 1); for (int i = 1; i <= n; ++i) { pref[i] = in[i].first + pref[i - 1]; } if (in[1].first != in[n].first) { ans[in[n].second] = true; for (int i = n - 1; i >= 1; --i) { if (in[i].first == in[1].first) { break; } if (pref[i] <= in[i + 1].first) { break; } ans[in[i].second] = true; } } for (int i = 1; i <= n; ++i) printf(ans[i] ? "T" : "N"); puts(""); 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 | #include <bits/stdc++.h> using namespace std; const int N = 500'007; int n; bool ans[N]; long long pref[N]; pair <int, int> in[N]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", &in[i].first); in[i].second = i; } sort(in + 1, in + n + 1); for (int i = 1; i <= n; ++i) { pref[i] = in[i].first + pref[i - 1]; } if (in[1].first != in[n].first) { ans[in[n].second] = true; for (int i = n - 1; i >= 1; --i) { if (in[i].first == in[1].first) { break; } if (pref[i] <= in[i + 1].first) { break; } ans[in[i].second] = true; } } for (int i = 1; i <= n; ++i) printf(ans[i] ? "T" : "N"); puts(""); return 0; } |