#include <bits/stdc++.h> using namespace std; int n, lst_n; long long dp[500005]; pair < int, int > p[500005]; bool b[500005]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &p[i].first); p[i].second = i; } sort(p, p + n); if(p[0].first == p[n - 1].first) { for (int i = 0; i < n; i++) { printf("N"); } return 0; } for (int i = 0; i < n; ++i) { dp[i] = dp[i - 1] + p[i].first; if(p[i].first == p[i - 1].first && lst_n == i - 1) { ++lst_n; continue; } if(dp[i] <= p[i + 1].first && i != n - 1) { lst_n = i; } } for (int i = lst_n; i >= 0; --i) { b[p[i].second] = 1; } for (int i = 0; i < n; i++) { if(b[i]) printf("N"); else { printf("T"); } } 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 | #include <bits/stdc++.h> using namespace std; int n, lst_n; long long dp[500005]; pair < int, int > p[500005]; bool b[500005]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &p[i].first); p[i].second = i; } sort(p, p + n); if(p[0].first == p[n - 1].first) { for (int i = 0; i < n; i++) { printf("N"); } return 0; } for (int i = 0; i < n; ++i) { dp[i] = dp[i - 1] + p[i].first; if(p[i].first == p[i - 1].first && lst_n == i - 1) { ++lst_n; continue; } if(dp[i] <= p[i + 1].first && i != n - 1) { lst_n = i; } } for (int i = lst_n; i >= 0; --i) { b[p[i].second] = 1; } for (int i = 0; i < n; i++) { if(b[i]) printf("N"); else { printf("T"); } } return 0; } |