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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// 
#include <bits/stdc++.h>

using namespace std;
#define FOR(n, u) for(int (n) = 1; (n) <= (u); n++)

constexpr int max_n = 500002;
typedef unsigned long long ull;
struct Sum{
    ull waga, nr;
};
Sum * tab;

bool sort1(Sum a, Sum b)
{
    return a.waga < b.waga;
}

bool sort2(Sum a, Sum b){
    return a.nr < b.nr;
}

bool check(int x, int n){
    ull suma = tab[x].waga;
    FOR(i, x - 1){
        if(suma <= tab[i].waga){
            return 0;
        }
        suma += tab[i].waga;
    }
    //cout << suma << " ";
    int i = x + 1;
    bool czy = 0;
    while(i <= n){
        if(suma > tab[i].waga)
            suma += tab[i].waga;
        else{
            czy = 1;
            break;
        }
        i++;
    }
    //cout << suma << " -> " << czy << endl;
    if(czy == 1)
        return 0;
    return 1;
}

int bs(ull n){
    ull lo = 1, hi = n, mid;
    while(lo < hi){
        mid = (lo + hi) / 2;
     //  cout << mid << endl;
        if(!check(mid, n)) lo = mid + 1;
        else hi = mid;
    }
    return lo;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    tab = new Sum[n + 1];
    FOR(i, n){
        cin >> tab[i].waga;
        tab[i].nr = i + 1;
    }
    sort(tab + 1, tab + n + 1, sort1);
    int w = tab[bs(n)].waga;
    if(!check(n, n)){
        FOR(i, n)
        cout << "N";
        return 0;
    }
    sort(tab + 1, tab + n + 1, sort2);
    FOR(i, n){
        if(tab[i].waga >= w){
            cout << "T";
        }
        else
        cout << "N";
    }
    return 0;
}