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

const int MAX = 500001;
int n, a[MAX], s[MAX];

bool is_king(int m) {
    long long sum = s[m];
    for (int i = 0; i < n; i++) {
        if (i != m) {
            if (sum > s[i]) 
                sum += s[i]; 
            else 
                return false;
        }
    }
    return true;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    copy(a, a+n, s);
    sort(s, s+n);
    //for (int i = 0; i < n; i++) cout << s[i]; cout << endl;
    int l = 0, p = n;
    while (l + 1 < p) {
        int m = (l + p) / 2;
        //cout << m << ": " << is_king(m) << endl;
        if (is_king(m)) p = m; else l = m;
    }
    //cout << l << " " << p << endl;
    for (int i = 0; i < n; i++)
        if (a[i] > s[l]) cout << 'T'; else cout << 'N';
    cout << endl;
    return 0;
}