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
#include <bits/stdc++.h>
#define ll long long
#define pli pair<ll,int>
#define fi first
#define se second
using namespace std;

void testcase() {
	int n;
	cin >> n;
	vector <pli> A(n);
	for (int i = 0; i < n; i++) {
		cin >> A[i].fi;
		A[i].se = i;
	}
	sort(A.begin(), A.end());
	vector <ll> Pref(n+1);
	Pref[0] = 0;
	for (int i = 0; i < n; i++) {
		Pref[i+1] = Pref[i] + A[i].fi;
	}
	
	int l;
	for ( l = n-1; l > 0; l--) {
		if (A[0].fi >= A[l].fi || (l+1 < n && Pref[l+1] <= A[l+1].fi)) {
			break;
		}
	}
	string ans(n, 'N');
	for (int i = n-1; i > l; i--) {
		ans[A[i].se] = 'T';
	}
	cout << ans <<endl;
}

int main() 
{
	ios_base::sync_with_stdio(false);
	testcase();
	return 0;
}