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
52
53
54
55
56
57
58
59
60
//Autor: Bartłomiej Czarkowski
#include <bits/stdc++.h>

using namespace std;

const int N = 5e5 + 7;
int n;
int t[N];
int p[N];

bool check(int x) {
	long long masa = p[x];
	for (int i = 1; i < x; ++i) {
		if (masa > p[i]) {
			masa += p[i];
		}
		else {
			return false;
		}
	}
	for (int i = x + 1; i <= n; ++i) {
		if (masa > p[i]) {
			masa += p[i];
		}
		else {
			return false;
		}
	}
	return true;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &t[i]);
		p[i] = t[i];
	}
	sort(p + 1, p + 1 + n);
	p[n + 1] = 1e9 + 7;
	int bp = 1, bk = n + 1, bs;
	while (bk - bp > 1) {
		bs = (bp + bk) / 2;
		if (check(bs)) {
			bk = bs;
		}
		else {
			bp = bs;
		}
	}
	for (int i = 1; i <= n; ++i) {
		if (t[i] >= p[bk]) {
			printf("T");
		}
		else {
			printf("N");
		}
	}
	printf("\n");
	return 0;
}