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
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

bool check(const vector<pair<ll, int>> &s, int p) {
    ll w = s[p].first;
    int e = 0;
    for(int i = 0; i < s.size(); i++) {
        if(i != p) {
            if(s[i].first < w) {
                w += s[i].first;
                e++;
            }
        }
    }

    return e == s.size() - 1;
}

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

    int n;
    cin >> n;
    vector<pair<ll, int>> a(n);
    vector<ll> raw;
    for(int i = 0; i < n; i++) {
        ll buff;
        cin >> buff;
        a[i] = {buff, i};
        raw.push_back(buff);
    }

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

    int p = 0;
    int q = a.size() - 1;
    ll best = 2e9;
    while(p <= q) {
        int m = (p + q)/2;

        if(check(a, m)) {
            q = m - 1;
            best = min(best, a[m].first);
        } else {
            p = m + 1;
        }
    }

    for(auto i: raw) {
        cout << (i >= best ? 'T' : 'N');
    }
    cout << "\n";

    return 0;
}