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

using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vector<pair<ll, int>> sums(n);
    vector<char> ans(n, 'N');

    for (int i = 0; i < n; i++){
        cin >> sums[i].first;
        sums[i].second = i;
    }

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

    ll act = sums[0].first, pref = sums[0].first, beg = 1;
    for (int i = 1; i < n; i++){
        pref += sums[i].first;
        if (act == sums[i].first){
            if (sums[i-1].first == sums[i].first)
                beg = i+1;
            else{
                beg = i;
                act = pref;
            }
        }
        else if (act < sums[i].first){
            beg = i;
            act = pref;
        }
        else{
            act = pref;
        }
    }

    for (; beg < n; beg++)
        ans[sums[beg].second] = 'T';

    for (auto& ch : ans)
        cout << ch;
    cout << "\n";
    
    return 0;
}

/*

*/