#define make_pair mp #define emplace_back pb #include <bits/stdc++.h> using namespace std; mt19937 mt_rand(time(0)); const int N = 5e5 + 5; int n, tab[N], t[N]; bool check(int x) { long long sum = tab[x]; for(int i=1;i<=n;i++) { if(i == x) continue; if(sum <= tab[i]) { return 0; } sum += tab[i]; } return 1; } int bin(int p, int k) { if(p == k) return p; int mid = (p + k) / 2; if(check(mid)) return bin(p, mid); return bin(mid + 1, k); } int main() { scanf("%d", &n); for(int i=1;i<=n;i++) { scanf("%d", &tab[i]); t[i] = tab[i]; } sort(tab + 1, tab + n + 1); int res = bin(1, n); long long maks = 0; if(res == n) { if(check(n)) maks = tab[res]; else maks = 1e9 + 5; } else maks = tab[res]; for(int i=1;i<=n;i++) { if(t[i] >= maks) printf("T"); else printf("N"); } 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 | #define make_pair mp #define emplace_back pb #include <bits/stdc++.h> using namespace std; mt19937 mt_rand(time(0)); const int N = 5e5 + 5; int n, tab[N], t[N]; bool check(int x) { long long sum = tab[x]; for(int i=1;i<=n;i++) { if(i == x) continue; if(sum <= tab[i]) { return 0; } sum += tab[i]; } return 1; } int bin(int p, int k) { if(p == k) return p; int mid = (p + k) / 2; if(check(mid)) return bin(p, mid); return bin(mid + 1, k); } int main() { scanf("%d", &n); for(int i=1;i<=n;i++) { scanf("%d", &tab[i]); t[i] = tab[i]; } sort(tab + 1, tab + n + 1); int res = bin(1, n); long long maks = 0; if(res == n) { if(check(n)) maks = tab[res]; else maks = 1e9 + 5; } else maks = tab[res]; for(int i=1;i<=n;i++) { if(t[i] >= maks) printf("T"); else printf("N"); } return 0; } |