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

#define st first
#define nd second
using pii = pair<int, int>;
using ll = long long;

const int N = 5e5 + 7;
pii as[N];
char ans[N];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &as[i].st);
        as[i].nd = i;
    }

    sort(as, as + n);

    int j = 1;
    ll s = as[0].st;
    ans[as[0].nd] = 'N';
    bool d = false;
    for (int i = 1; i < n; ++i) {
        auto [a, idx] = as[i];
        if (i == j) {
            s += a;
            ++j;
        }
        d |= a != as[i - 1].st;
        while (j < n && as[j].st < s)
            s += as[j++].st;
        if (d && j == n)
            ans[idx] = 'T';
        else
            ans[idx] = 'N';
    }

    for (int i = 0; i < n; ++i)
        printf("%c", ans[i]);

    return 0;
}