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
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<long long> getPrefSums(const vector<pair<int, int> >& wagi, int n) {
    vector<long long> res(n);

    res[0] = wagi[0].first;
    for(int i = 1; i < n; ++i) {
        res[i] = res[i - 1] + wagi[i].first;
    }

    return res;
}

int main() {
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<pair<int, int> > wagi(n);
    vector<bool> res(n);
    for(int i = 0; i < n; ++i) {
        cin >> wagi[i].first;
        wagi[i].second = i;
    }
    sort(wagi.begin(), wagi.end());

    vector<long long> prefs = getPrefSums(wagi, n);

    for(int i = n - 1; i > 0; --i) {
        if(wagi[0].first == wagi[i].first || (i < n - 1 && prefs[i] <= wagi[i + 1].first)) break;
        res[wagi[i].second] = true;
    }
    
    for(int i = 0; i < n; ++i) {
        cout << (res[i] ? 'T' : 'N');
    }
    cout << "\n";
}