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
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <time.h>
#include <queue>

using namespace std;

int main () {
	int n;
	scanf("%d", &n);
	vector<pair<int64_t, int> > sums;
	for (int i = 0; i < n; ++i) {
		int64_t w;
		scanf("%lld", &w);
		sums.push_back(make_pair(w, i));
	}
	sort(sums.begin(), sums.end());
	vector<int64_t> psums;
	int64_t psum = 0;
	for (int i = 0; i < n; ++i) {
		psum += sums[i].first;
		psums.push_back(psum);
	}
	int i = 0;
	while ((i < n) && (sums[i].first == sums[0].first)) {
		psums[i] = 0;
		++i;
	}
	vector<bool> ok(n, false);
	if ((sums[n - 1].first != sums[0].first) || (n == 1)) {
		ok[sums[n - 1].second] = true;
	}
	for (int i = n - 2; i >= 0; --i) {
		if (psums[i] <= sums[i + 1].first) {
			break;
		}
		ok[sums[i].second] = true;
	}
	for (int i = 0; i < n; ++i) {
		printf(ok[i] ? "T" : "N");
	}
	printf("\n");
	return 0;
}