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
#include <bits/stdc++.h>

using namespace std;
pair<long long,int> T[500500];
long long Pre[500500];
char W[500500];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>T[i].first;
        T[i].second=i;
    }
    for(int i=0;i<=n;i++){
        W[i]='N';
    }
    sort(T+1,T+n+1);
    long long sum=0;
    for(int i=1;i<=n;i++){
        sum = sum+T[i].first;
        Pre[i]=sum;
    }
    for(int i=n;i>=0;i--){
        //cout<<Pre[i]<<" "<<T[i].first<<"\n";
        if(Pre[i]>T[i+1].first and (i==n or W[T[i+1].second]=='T')){
            W[T[i].second]='T';
        }
    }
    long long spr = T[1].first;
    int j =2;
    if(n>1 and T[j].first==spr){
        while(j<=n and T[j].first==spr){
            W[T[j].second]='N';
            j++;
        }
    }
    for(int i=1;i<=n;i++){
        cout<<W[i];
    }
    cout<<"\n";
    return 0;


}