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
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<bits/stdc++.h>
#define ST first
#define ND second
#define ll long long

using namespace std;

int n;
vector<pair<ll,int> > tab;

bool check(int x){
	ll sum = tab[x].ST;
	vector<bool> tmp(n);
	tmp[x] = 1;
	for(int i = 0; i < x; i++){
		if(sum > tab[i].ST){
			sum += tab[i].ST;
			tmp[i] = 1;
		}
	}
	for(int i = 0; i < n; i++){
		if(tmp[i]) continue;
		if(sum > tab[i].ST){
			tmp[i] = 1;
			sum += tab[i].ST;
		}
	}
	bool ok = true;
	for(int i = 0; i < n; i++){
		ok &= tmp[i];
	}
	return ok;
}

int main() {
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
    
    cin >> n;
    for(int i = 0; i < n; i++){
    	ll x; cin >> x;
    	tab.push_back({x,i});
    }
    
    sort(tab.begin(),tab.end());

	int l = -1, r = n;
	while(l + 1 < r){
		int mid = (l+r)/2;
		if(check(mid)) r = mid;
		else l = mid;		
	}
	
	string ans = "";
	while(ans.size() != n) ans += 'T';
	
	for(int i = 0; i <= l; i++) ans[tab[i].ND] = 'N';
	
	cout << ans << "\n";
	
    return 0;
}