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 <algorithm>
#include <cstdio>

using namespace std;

const int MAXN = 500000 + 1;

typedef pair<int, bool> PIB;
typedef pair<int, PIB> PIIB;
typedef long long LL;

PIIB a[MAXN];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i].first);
        a[i].second.first = i;
        a[i].second.second = false;
    }

    if (n == 1) {
        printf("T\n");
        return 0;
    }

    sort(a, a + n);

    LL sum = a[0].first;
    a[0].second.second = false;

    bool can_start = false;
    for (int i = 1; i < n; i++) {
        sum += a[i].first;

        if (a[i].first != a[i - 1].first && !can_start) {
            can_start = true;
        }
        if (!can_start) {
            continue;
        }
        int j = i + 1;
        while (j < n && a[j].first < sum) {
            sum += a[j].first;
            j++;
        }

        if (j == n) {
            for (int j = i; j < n; j++) a[j].second.second = true;
            break;
        } else {
            i = j - 1;
        }
    }

    for (int i = 0; i < n; i++) swap(a[i].first, a[i].second.first);
    sort(a, a + n);
    for (int i = 0; i < n; i++) printf("%c", a[i].second.second ? 'T' : 'N');
    printf("\n");
}