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

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    bool check = true;
    long long prefix_sum[500007] = {};
    bool wyn[500007] = {};
    pair<long long, long long> t[500007] = {};
    cin >> n;
    for (int i = 0; i< n; i++) {
        cin >> t[i].first;
        t[i].second = i;

    }
    sort(t, t+n);
    for (int i = 1; i <= n; i++) {
        if (t[i] != t[i-1]) {
            check = true;
        }
    }
    prefix_sum[0] = t[0].first;
    for (int i = 1; i < n; i++) {
        prefix_sum[i] = prefix_sum[i-1] + t[i].first;
    }
    for (int i = n-2; i >= 0; i--) {
        if (t[i].first == t[i+1].first) {
            prefix_sum[i]=prefix_sum[i+1];
        }
    }
    if (t[0].first == t[1].first) {
        for (int i = 0; i < n; i++) {
            if (t[i].first == t[i+1].first) {
                prefix_sum[i] = 0;
                prefix_sum[i+1] = 0;
            }
        }
    }
    if (check == true) {
        wyn[t[n-1].second] = true;
        for (int i = n-2; i >= 0; i--) {
            if (prefix_sum[i] > t[i+1].first) {
                wyn[t[i].second] = true;
            } else {
                wyn[t[i].second] = false;
                break;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        if (wyn[i] == true) {
            cout << "T";
        } else {
            cout << "N";
        }
    }
}