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
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

char wyn[500100];

int main() {
    long long sum = 0;
    int n = 0, x = 0;

    vector<pair<int, int>> sums;

    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &x);
        sum += x;
        sums.emplace_back(x, i);
    }


    sort(sums.begin(), sums.end());

    int smallest = sums[0].first;

    wyn[sums[n - 1].second] = sums[n - 1].first == smallest ? 'N' : 'T';
    sum -= sums[n - 1].first;

    for (int i = n - 2; i >= 0; i--) {
        if (sums[i].first > smallest) {
            wyn[sums[i].second] =
                    (wyn[sums[i + 1].second] == 'T' && sum > sums[i + 1].first)
                    ? 'T' : 'N';
        } else {
            wyn[sums[i].second] = 'N';
        }

        sum -= sums[i].first;
    }

    printf("%s", wyn);

}