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
62
63
64
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
int t[500005], stare[500005];
ll pref[500005];
vector<int> ord;
bool comp(int a, int b) {
    return t[a] < t[b];
}

ll sum(int a, int b) {
    return pref[b] - pref[a - 1];
}

bool check(int x) {
    ll masa = t[x];
    for (int i = 1; i <= n; i++) {
        if (i == x) continue;
        if (t[i] >= masa) return false;
        masa += t[i];
    }

    return true;
}

int32_t main() {
    ios_base::sync_with_stdio(0);

    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> t[i];
        stare[i] = t[i];
    }

    sort(t + 1, t + n + 1);

    if (!check(n)) {
        for (int i = 1; i <= n; i++) cout << "N";
        cout << "\n";

        return 0;
    }

    if (check(1)) {
        for (int i = 1; i <= n; i++) cout << "T";
        cout << "\n";

        return 0;
    }

    int lo = 1, hi = n;
    while (lo < hi) {
        int mid = (lo + hi) >> 1;
        if (check(mid)) hi = mid;
        else lo = mid + 1;
    }

    for (int i = 1; i <= n; i++) {
        cout << (stare[i] >= t[lo] ? "T" : "N");
    }

    cout << "\n";
}