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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> sums, sortedSums;
    sums.resize(n);
    sortedSums.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> sums[i];
        sortedSums[i] = sums[i];
    }
    sort(begin(sortedSums), end(sortedSums));
    int idx{};
    long long s = sortedSums[0];
    while (idx < n - 1 && sortedSums[idx + 1] == sortedSums[0]) {
        s += sortedSums[++idx];
    }
    if (idx == n - 1) {
        for (int i = 0; i < n; ++i) {
            cout << 'N';
        }
        return 0;
    }
    int p{};
    for (;;) {
        s += sortedSums[++idx];
        p = idx;
        while (idx < n - 1 && sortedSums[idx + 1] < s) {
            s += sortedSums[++idx];
        }
        if (idx == n - 1) {
            break;
        }
    }
    for (int i = 0; i < n; ++i) {
        std::cout << (sums[i] >= sortedSums[p] ? 'T' : 'N');
    }
    return 0;
}