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
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int N = 500005;

int tab[N], sm, kol[N], i, n, can[N], w, w2;
LL sum;

bool cmp(int a, int b) {
	return tab[a] < tab[b];
}

int main() {
scanf("%d", &n);
sum = 0;
for (i=0;i<n;i++) {
	scanf("%d", &tab[i]);
	kol[i] = i;
	can[i] = 0;
	sum += tab[i];
}
sort(kol, kol + n, cmp);
sm = tab[kol[0]];

for (i=n-1;i>=0;i--) {
	w = kol[i];
	w2 = kol[i + 1];
	sum -= tab[w];
	if (tab[w] == sm) break;
	if (i != n - 1 && sum + tab[w] <= tab[w2]) break;
	can[w] = 1;
}

for (i=0;i<n;i++) if (can[i]) printf("T"); else printf("N");
printf("\n");
return 0;
}