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

#define boost                     \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)

bool can_solve(vector<int> &v, int pos) {
    long long int sum = v[pos];

    for (int i = 0; i < v.size(); ++i) {
        if (i == pos) continue;
        if (v[i] >= sum)
            return false;
        sum += v[i];
    }
    return true;
}

int main() {
    boost;
    int n; cin >> n;
    vector<int> a(n);

    for (int i = 0; i < n; ++i) cin >> a[i];

    vector<int> sorted(a);
    sort(sorted.begin(), sorted.end());
    int l = 0, r = n - 1;

    if (!can_solve(sorted, n - 1)) {
        l = r = n;
    }

    while (l < r) {
        int mid = (l + r) / 2;
        if (can_solve(sorted, mid))
            r = mid;
        else
            l = mid + 1;
    }

    int thresh = l < n ? sorted[l] : INT_MAX;
    for (int i = 0; i < n; ++i)
        cout << (a[i] >= thresh ? 'T' : 'N');
    cout << '\n';

    return 0;
}