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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin >> n;
    
    if (n == 1) {
        cout << "T\n";
        return 0;
    }
    if (n == 2) {
        int a, b;
        cin >> a >> b;
        if (a > b) {
            cout << "TN\n";
        } else if (b > a) {
            cout << "NT\n";
        } else {
            cout << "NN\n";
        }
        return 0;
    }
    
    vector<long long> ryby(n);
    for (auto& r : ryby) {
        cin >> r;
    }
    auto org(ryby);
    sort(ryby.begin(), ryby.end());
    
    int min_pointer = 0;
    auto res = LONG_LONG_MAX;
    
    auto pot_res = 0LL;
    
    auto prev_r = -1;
    
    for (int r = 0; r < n; ) {
        int iter = 0;
        if (r != prev_r) {
            pot_res = ryby[r];
            prev_r = r;
        }
        while (min_pointer < r && ryby[r] > ryby[min_pointer]) {
            ryby[r] += ryby[min_pointer];
            ryby[min_pointer] = 0;
            min_pointer++;
            iter++;
        }
        
        auto j = r + 1;
        while (j < n && ryby[j] < ryby[r]) {
            swap(ryby[j], ryby[r]);
            r = j;
            j++;
        }
        prev_r = r;
        
        if (r == n - 1) {
            if (ryby[r - 1] == 0) {
                res = pot_res;
            }
        }
        
        if (ryby[r] <= ryby[min_pointer]) {
            r++;
        }
    }
    
    for (auto x : org) {
        if (x >= res) {
            cout << 'T';
        } else {
            cout << 'N';
        }
    }
    cout << '\n';

    return 0;
}