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
#include <bits/stdc++.h>
using namespace std;
const int MAXI = 5e5 + 7;
long long tab[MAXI], tab1[MAXI];
bool Result(long long a, int j, int n){
    bool b = true;
    for(int i = 0; i < n; i++){
        if (j != i){
            if (a > tab[i]) a += tab[i];
            else{
                b = false;
                break;
            }
        }
    }
    return b;
}

int BinarySearchResult(int pocz, int kon, int n)
{
    int sro;
    while(pocz < kon)
    {
        sro = (pocz + kon) / 2;
        if(Result(tab[sro], sro, n) == false)
        {
            pocz = sro + 1;
        }
        else
        {
            kon = sro;
        }
    }
    return tab[pocz];
}

int main()
{
    ios_base::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    int n,k;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> tab[i];
        tab1[i] = tab[i];
    }
    sort(tab, tab + n);
    k = BinarySearchResult(0, n - 1, n);
    if (k == tab[0]){
        if (Result(k , 0, n) == false) k = 1e9 + 9;
    }
    for(int i = 0; i < n; i++){
        if(tab1[i] >= k) cout << "T";
        else cout << "N";
    }

    return 0;
}