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

using namespace std;


int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n;
    cin >> n;

    vector<vector<int>> weights(n, vector<int>(2));
    vector<uint64_t> cumsums(n);

    int num;
    for (int i = 0; i < n; ++i) {
        cin >> num;
        weights[i] = {num, i};
    }
    sort(weights.begin(), weights.end());

    uint64_t sum = 0;
    int first = weights[0][0];
    for (int i = 0; i < n; ++i) {
        sum += weights[i][0];
        if (weights[i][0] == first) {
            cumsums[i] = weights[i][0];
        }
        else {
            cumsums[i] = sum;
        }
    }

    string res(n, 'T');
    bool possible = true;
    for (int i = n - 2; i >= 0; --i) {
        if (cumsums[i] < weights[i + 1][0] || !possible) {
            res[weights[i][1]] = 'N';
            possible = false;
        }
    }
    res[weights[n - 1][1]] = weights[n - 1][0] != weights[0][0] ? 'T' : 'N';

    cout << res;

    return 0;
}