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

bool is_valid(int eater, const vector<int> &sorted) {
	int64_t mass = sorted[eater];
	
	for (int j = 0; j < sorted.size(); j++) {
		if (j == eater) continue;
		
		if (sorted[j] >= mass) return false; // won't eat any more
		mass += sorted[j];
	}
	
	return true;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int n; cin >> n;
	
	vector<int> sumy(n);
	for (int &i : sumy) cin >> i;
	
	vector<int> sortowane(sumy);
	sort(sortowane.begin(), sortowane.end());
	
	int i = 0, j = n;
	while (i != j) {
		int mid = (i + j) / 2;
		
		if (is_valid(mid, sortowane)) j = mid;
		else i = mid + 1; 
	}
	
	int treshold = i < n ? sortowane[i] : 1e9 + 10;
	for (int i : sumy)
		cout << (i >= treshold ? 'T' : 'N');
	cout << endl;
	
	return 0;
}