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

#define vi vector<int>
#define f first
#define s second
#define sz(s) (int)s.size()
#define pb push_back
#define ii pair<int,int>
#define vii vector<ii>

bool moge(vii & ryby, int poz){
    long long w = ryby[poz].f;

    for(int i = 0; i < sz(ryby); i++){
        if(i == poz)
            continue;

        if(ryby[i].f < w){
            w += ryby[i].f;
        }
        else{
            return false;
        }
    }
    return true;
}

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

    int n;
    cin >> n;

    vector<pair<int, int> > ryby;
    for(int i = 0; i < n; i++){
        int ryba;;
        cin >> ryba;
        ryby.pb({ryba, i});
    }

    sort(ryby.begin(), ryby.end());

    int l = 0;
    int r = n;

    while(r - l > 1)
        (moge(ryby, (r + l) / 2) ? r : l) = (l + r) / 2;
    

    vi ans(n);
    for(int i = r; i < n; i++)
        ans[ryby[i].s] = 1;

    for(int i = 0; i < sz(ans); i++)
        cout << (ans[i] ? 'T' : 'N');
    cout << '\n';

    return 0;
}