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
#include <iostream>
#include <algorithm>
#include <iterator>

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int n;

    cin >> n;

    int sums[n], sums2beSorted[n], current_king_val;
    long long prefixSums2[n], prefix_sum = 0;

    for (auto i = 0; i < n; i++) {
        cin >> sums[i];
    }

    copy(sums, sums + n, sums2beSorted);

    sort(sums2beSorted, sums2beSorted + n);
    
    current_king_val = -1;
    prefix_sum = sums2beSorted[0];
    for (auto i = 1; i < n; i++) {
        if (sums2beSorted[i] != sums2beSorted[i - 1] && (prefix_sum <= sums2beSorted[i] || sums2beSorted[i - 1] == sums2beSorted[0])) {
            current_king_val = sums2beSorted[i];
        }

        prefix_sum += sums2beSorted[i];
    }

    if (current_king_val == -1) {
        current_king_val = sums2beSorted[0] + 1;
    }

    for (auto x: sums) {
        if (x >= current_king_val) {
            cout << "T";
        } else {
            cout << "N";
        }
    }


    return 0;
}