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
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool cmp(pair<int, int> a, pair<int, int> b) {
	return a.first < b.first;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<pair<int, int>> input(n);
	for (int i = 0; i < n; i++) { cin >> input[i].first; input[i].second = i; }
	sort(input.begin(), input.end(), cmp);
	vector<long long> sp(n);
	sp[0] = input[0].first;
	for (int i = 1; i < n; i++) sp[i] = sp[i - 1] + input[i].first;
	//for (auto i : input) cout << i.first << "," << i.second << " "; cout << endl;
	//for (auto i : sp) cout << i << " "; cout << endl;
	vector<bool> ans(n,false);
	ans[input.back().second] = (input[0].first < input[n - 1].first);
	int i = n - 1;
	while (i > 0 && ans[input[i].second]) {
		i--;
		ans[input[i].second] = (sp[i] > input[i + 1].first && input[i].first>input[0].first );
		//cout << "(" << i << "/" << input[i].first << "/" << input[0].first << ")";
	}
	//for (int i = 0; i < n; i++) cout << ans[i];
	for (auto j : ans) {if (j)  cout << 'T'; else cout << 'N';  }
	return 0;
}