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

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    long long n;
    cin>>n;
    vector<pair<long long,long long>> v(n);
    for(long long i=0; i<n; ++i)
    {
        cin>>v[i].first;
        v[i].second=i;
    }
    sort(v.begin(),v.end());

    vector<long long> pref(n,0);
    pref[0]=v[0].first;
    for(long long i=1; i<n; ++i)
        pref[i]=pref[i-1]+v[i].first;
    
    vector<int> dp(n,-1);
    if(v[0].first<v[n-1].first)
        dp[v[n-1].second]=1;
    for(long long i=n-2; i>0; --i)
        if(v[0].first<v[i].first&&pref[i]>v[i+1].first&&dp[v[i+1].second]==1) 
            dp[v[i].second]=1;
    
    for(long long i=0; i<n; ++i)
        if(dp[i]==1)
            cout<<"T";
        else
            cout<<"N";
    cout<<endl;

    return 0;
}