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

int n;
long long required_weight = 0LL;
long long sum[500007];
long long weight[500007];

bool test(int id) {
    long long current_weight = weight[id];
    for (int i = 0; i < n; i++) {
        if (i == id) {
            continue;
        }
        if (current_weight > weight[i]) {
            current_weight += weight[i];
        }
        else {
            return false;
        }
    }
    return true;
}

long long bs() {
    int L = 0, R = n - 1;
    while (L < R) {
        int S = (L + R + 1) / 2;
        test(S) ? (R = S - 1) : (L = S);
    }
    return weight[L];
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> sum[i];
        weight[i] = sum[i];
    }

    sort(weight, weight + n);

    required_weight = bs();

    for (int i = 0; i < n; i++) {
        cout << (sum[i] > required_weight ? 'T' : 'N');
    }
    return 0;
}