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
#include <bits/stdc++.h>
using namespace std;
#define nd second
#define st first
#define pii pair<int,int>
#define pb push_back
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(); cout.tie();

    int n;
    cin>>n;
    vector<ll>v(n);
    for(int i=0; i<n; i++)
        cin>>v[i];
    
    map<int,vector<int>>m;
    for(int i=0; i<n; i++)
        m[v[i]].pb(i);

    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());

    vector<ll>prefsum(n);
    prefsum[0]=v[0]*(ll(m[v[0]].size()));
    for(int i=1; i<v.size(); i++)
        prefsum[i]=prefsum[i-1]+ll(v[i])*(ll(m[v[i]].size()));

    vector<bool>ans(n);
    for(int i=v.size()-1; i>0; i--){
        for(auto x:m[v[i]])
            ans[x]=true;

        if(v[i]>=prefsum[i-1])
            break;
    }
    
    for(auto x:ans){
        if(x==false) cout<<"N";
        else cout<<"T";
    }
}