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

using namespace std;

int main() {
    int n;
    cin>>n;
    vector< pair<long long,int> > a;
    for(int i=0; i<n; ++i) {
        long long A;
        cin>>A;
        a.push_back(make_pair(A,i));
    }
    sort(a.begin(),a.end());
    long long tab[500000];
    long long suma = 0;
    for(int i=0; i<n; ++i) {
        suma += a[i].first;
        tab[i] = suma;
    }
    int ans = n;
    if(a[0].first != a[n-1].first) ans--;
    else {
        for(int i=0; i<n; ++i) cout<<"N";
        return 0;
    }
    while(true) {
        if(ans == 0) break;
        if(tab[ans-1] > a[ans].first && a[ans-1].first > a[0].first) ans--;
        else break;
    }
    char b[500000];
    for(int i=0; i<n; ++i) {
        if(i < ans) b[a[i].second] = 'N';
        else b[a[i].second] = 'T';
    }
    for(int i=0; i<n; ++i) cout<<b[i];
    
    cout<<endl;
    return 0;
}