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

long long n,x,y,ind,sr,indf,test;
pair<long long,long long>P[500005];
pair<long long,long long>res[500005];

int finds(int l, int r){
	while(l!=r){
		sr=(l+r)/2;
		test=P[sr].first;
		for(int i=1;i<=n;i++){
            if(i==sr)continue;
            if(test>P[i].first){
                test+=P[i].first;
            }
            else {
                l=sr+1;
                break;
            }
            if(i==n)r=sr;
		}
    }
    return l;
}

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

	for(int i=1;i<=n;i++){
        cin>>x;
        P[i]={x,i};
	}
	sort(P+1,P+n+1);
	ind=finds(1,n);
	for(int i=1;i<=n;i++){
        res[i]={P[i].second,P[i].first};
	}
	sort(res+1,res+n+1);
	for(int i=1;i<=n;i++){
        if(res[i].second<=P[ind-1].first)cout<<"N";
        else cout<<"T";
	}
}