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
#include <iostream>
#include <algorithm>
#define ll long long int
using namespace std;

ll n;
pair<ll, ll> sum[500001];

bool sam[500001];
ll pre[500001];

bool wynik[500001];
bool pos[500001];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> sum[i].first;
		sum[i].second = i;
	}
	
	sort(sum, sum + n);
	
	pre[0] = sum[0].first;
	sam[0] = true;
	
	for(int i = 1; i < n; ++i){
		sam[i] = sam[i - 1] && (sum[i-1].first == sum[i].first);
		pre[i] = pre[i-1] + sum[i].first;
	}
	
	pos[n] = true;
	
	for(int i = n - 1; i >= 0; --i){
		if(pos[i+1] && (!sam[i]) && (pre[i] > sum[i+1].first)) pos[i] = true;
		wynik[sum[i].second] = pos[i];
	}
	
	//for(int i = 0; i < n; ++i){
	//	cout << i << "[" << sum[i].second << "]" << "(" << sum[i].first << "): " << sam[i] << ", " << pre[i] << " - " << pos[i] << endl;
	//}
	
	for(int i = 0; i < n; ++i){
		if(wynik[i]) cout << 'T';
		else cout << 'N';
	}
}