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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAX = 5e5+10;
int n, t[MAX], t2[MAX];
bool spr(int x)
{
	ll suma = t2[x];
	for(int i = 1; i <= n; i++)
	{
		if(i == x)
			continue;
		if(suma > t2[i])
			suma += t2[i];
		else
			return false;
	}
	return true;
}
int bin()
{
	int wynik = -1, pocz = 1, kon = n;
	while(pocz <= kon)
	{
		int sr = (pocz + kon) / 2;
		if(spr(sr))
			kon = sr - 1, wynik = sr;
		else
			pocz = sr + 1;
	}
	return wynik;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n;
	if(n == 1)
	{
		cout << "T\n";
		return 0;
	}
	for(int i = 1; i <= n; i++)
	{
		cin >> t[i];
		t2[i] = t[i];
	}
	sort(t2 + 1, t2 + n + 1);
	int mini = bin();
	for(int i = 1; i <= n; i++)
		if(mini != -1 && t[i] >= t2[mini])
			cout << "T";
		else
			cout << "N";
	cout << "\n";
}