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
65
66
67
68
69
70
71
72
73
#include <bits/stdc++.h>

using namespace std;

#define ll long long

template <typename T>
std::ostream & operator << (std::ostream & os, const std::vector<T> & vec) {
    for(auto elem : vec)
        os<<elem<< " ";
    return os;
}

int n;
vector<ll> a;
vector<int> id;

struct myclass {
    bool operator() (int i,int j) { return (a[i]<a[j]);}
} compare_mass;

bool is_king(int j) {
    ll mass = a[id[j]];

    int i = 0;

    while (i < n and (i == j or mass > a[id[i]])) {
        if (i != j)
            mass += a[id[i]];
        ++i;
    }

    return (i == n);
}


int main() {
    cin >> n;

    a.resize(n);

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

    for (int i=0; i<n; ++i)
        id.push_back(i);

    sort(id.begin(), id.end(), compare_mass);

    int l = 0;
    int u = n - 1;

    int smallest_king = n;

    while (l <= u) {
        int m = (l + u) / 2;
        if (is_king(m)) {
            smallest_king = min(smallest_king, m);
            u = m - 1;
        }
        else
            l = m + 1;
    }

    string res(n, 'N');

    for (int i = smallest_king; i<n; ++i)
        res[id[i]] = 'T';

    cout << res;

    return 0;
}