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

struct sum {
    int weight;
    int idx;
    bool king;
};

int n;
sum s[500001];
long long pref[500001];

int main() {
    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> s[i].weight;
        s[i].idx = i;
        s[i].king = false;
    }
    sort(s,s+n,[](sum a, sum b){return a.weight < b.weight;});
    s[n].weight = -1;
    pref[0] = s[0].weight;
    for(int i=1; i<n; i++) {
        pref[i] = pref[i-1] + s[i].weight;
    }
    for(int i=n-1; i>=0; i--) {
        if(pref[i] > s[i+1].weight && s[i].weight != s[0].weight) {
            s[i].king = true;
        } else {
            break;
        }
    }
    sort(s,s+n,[](sum a, sum b){return a.idx < b.idx;});
    for(int i=0; i<n; i++) {
        cout << (s[i].king ? "T" : "N");
    }
}