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

bool can(vector<long long>& ordr, long long m) {
    long long elem = ordr[m];
    long long acc = elem;
    ordr[m] = 0;
    int idx = 0;
    while (idx < ordr.size() && ordr[idx] < acc) {
        acc += ordr[idx];
        idx += 1;
    }
    ordr[m] = elem;
    return idx == ordr.size();
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    vector<long long> orig;
    vector<long long> ordr;
    for (int i = 0; i < n; i++) {
        long long e;
        cin >> e;
        orig.push_back(e);
        ordr.push_back(e);
    }

    sort(ordr.begin(), ordr.end());
    long long a = 0, b = n - 1;
    while (a < b) {
        long long m = (a + b) / 2;
        if (can(ordr, m)) {
            b = m;
        }
        else {
            a = m + 1;
        }
    }
    bool possible = can(ordr, a);
    long long rest = ordr[a];
    for (int i = 0; i < n; i++) {
        if (possible && orig[i] >= rest) {
            cout << "T";
        }
        else {
            cout << "N";
        }
    }

    return 0;
}