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
#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long
#define pr pair<ll,ll>
#define fs first
#define sc second

const int MAX = 5e5+5;
pr in[MAX];
ll sum[MAX];
bool ans[MAX];

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    int n;
    bool ok = 1;
    bool same = 0;
    ll low = 1e10;
    cin >> n;

    for(int i = 1; i <= n; i++){
        cin >> in[i].fs;
        in[i].sc = i; 
        low = min(low, in[i].fs);
    }

    sort(in+1, in+n+1);
    
    for(int i = 1; i <= n; i++){
        sum[i] = sum[i-1] + in[i].fs;
    }

    for(int i = n; i >= 1; i--){
        if(sum[i] <= in[i+1].fs) ok = false;
        ans[in[i].sc] = ok;
        if(in[i].fs == low) ans[in[i].sc] = 0;

        //cout << in[i].sc << " " << in[i].fs << "   " << ans[in[i].sc] << "\n";
    }

    for(int i = 1; i <= n; i++)
        cout << (ans[i] ? 'T' : 'N');
}