1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <cstdio>
#include <algorithm>

using namespace std;
#define MAX 600000

long long S[MAX],v[MAX],w[MAX],n,l = 2000000000;

int main() {
    scanf("%lld", &n);
    for(int i=1;i<=n;i++) {
        scanf("%lld", &v[i]);
        w[i]=v[i];
    } 
    sort(v+1, v+n+1);
    for(int i=1;i<=n;i++) S[i] = S[i-1]+v[i];

    if (v[1] != v[n] || n == 1) l = v[n];
    for(int i=n;v[i] != v[1];i--) if (S[i] > l) l = v[i];

    for(int i=1;i<=n;i++) printf("%c" , w[i] >=l ? 'T' : 'N');
    printf("\n");
}