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
52
53
54
55
56
57
58
59
60
61
#include<bits/stdc++.h>

#define maxn 500010

using namespace std;

int tab[maxn], tab1[maxn];


bool spraw(int sr, int n) {
    //cout << "s" << endl;
    ++n;
    long long x = tab[sr];
    for (int i = 0; i < n; ++i) {
        if (i != sr) {
            if (tab[i] >= x)
                return false;
            else
                x += (long long)tab[i];
        }
    }
    return true;
}

int bnsrch(int k) {
    int n = k;
    int p = 0;
    while(p != k) {
        int sr = (p + k)/2;
        if (spraw(sr,n))
            k = sr;
        else
            p = sr+1;
  //      cout << p << endl;
    }
    if (spraw(p,n))
        return tab[p];
    else
        return tab[p] + 1;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        //cout << i << " " << n << endl;
        cin >> tab[i];
        tab1[i] = tab[i];
    }
    //puts("a");
    sort(tab, tab+n);
    int x = bnsrch(n-1);
    for (int i = 0; i < n; ++i) {
        if (tab1[i] >= x)
            cout << "T";
        else
            cout << "N";
    }
}