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
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int MAKS = 5*1e5 + 2;
const int MOD = 1e9+7;
ll tab[MAKS];
vector<ll> vec;
bool check(ll x)
{
    ll suma = 0;
    int id = 0;
    while(id < vec.size() && x > vec[id])
    {
        suma += vec[id];
        id++;
    }
    if(suma > 0)
    {
         while(id < vec.size() && x == vec[id])
        {
            suma += vec[id];
            id++;
        }
    }
    while(id < vec.size() && suma > vec[id])
    {
        suma += vec[id];
        id++;
    }
    if(id == vec.size())
    {
        return 1;
    }
    return 0;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n; cin >> n;

    for(int i = 0 ; i < n; i++)
    {
        cin >> tab[i];
        vec.pb(tab[i]);
    }

    sort(vec.begin(), vec.end());
    ll l = 0, p = 1e9 + 1;
    while(l < p)
    {
        ll m = (l+p)/2;
        if(check(m) == 0)
        {
            l = m+1;
        } else
        {
            p = m;
        }
    }
    //cout << l << "\n";
    for(int i = 0 ; i < n; i++)
    {
        if(tab[i] >= l) cout << "T";
        else cout << "N";
    }
}