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

void solve() {
    int n, s;
    multimap<long long, int> sizes; // size -> pos
    map<int, char> results; // pos -> res "T"/"N"
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s;
        sizes.insert({s, i});
    }
    vector<long long> psums(n, 0);
    int i = 0;
    for (const auto & el: sizes) {
        if (i == 0) {
            psums[i] = el.first;
        } else {
            psums[i] = psums[i-1] + el.first;
        }
        i++;
    }
    if (sizes.begin()->first == sizes.rbegin()->first) {
        string ret(n, 'N');
        cout << ret << "\n";
        return;
    }
    i = n - 1;
    auto prev = sizes.rbegin();
    for (auto it = sizes.rbegin(); it != sizes.rend(); it++) {
        if (it->first == psums[0]) {
            results[it->second] = 'N';
        } else if (it->first == sizes.rbegin()->first) {
            results[it->second] = 'T';
        } else {
            if (it->first < prev->first) {
                if (psums[i] > prev->first && results[prev->second] == 'T') {
                    results[it->second] = 'T';
                } else {
                    results[it->second] = 'N';
                }
            } else {
                results[it->second] = results[prev->second];
            }
        }
        prev = it;
        i--;
    }

    for (i = 0; i < n; i++) {
        cout << results[i];
    }
    cout <<"\n";

}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}