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
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e5 * 5 + 10;
long long pref[N];
bool res[N];
pair <int,int> t[N];
bool czy = false;
int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    for(int i = 0; i < n; i++){
        cin >> t[i].first;
        t[i].second = i;
        if(i && t[i].first != t[i-1].first)
            czy = true;
    }
    if(!czy){
        for(int i = 0; i < n; i++)
            cout << "N";
        cout << "\n";
        return 0;
    }
    sort(t,t + n);
    pref[0] = t[0].first;
    for(int i = 1; i < n; i++)
        pref[i] = t[i].first + pref[i-1];
    long long minimum = t[n-1].first;
    for(int i = n - 1; i >= 0; i--){
        long long x = t[i].first;
        if(t[i].first != t[0].first)
            x += pref[i-1];
        if(x > minimum)
            minimum = t[i].first,res[t[i].second] = 1;
    }
    for(int i = 0; i < n; i++)
        cout << (res[i] ? "T" : "N");
    cout << "\n";
}