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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <algorithm>
#include <cstdio>

using namespace std;

struct Fish
{
	int id;
	long long size;
	bool sameAsNext;

	bool operator <(const Fish& d) const
	{
		return size < d.size;
	}
};

Fish tab[500010];
bool res[500010];

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		res[i] = false;
		tab[i].sameAsNext = false;
		tab[i].id = i;
		scanf("%lld", &tab[i].size);
	}

	sort(tab, tab + n);

	long long sum = tab[0].size;

	res[tab[0].id] = false;
	int s = 1;
	while (s<n && tab[s].size == tab[s-1].size)
	{
		res[tab[s].id] = false;
		sum += tab[s].size;
		s++;
	}

	for (int i = s; i < n; i++)
	{

		sum += tab[i].size;

		if (sum > tab[n - 1].size)
		{
			res[tab[i].id] = true;
		}
		else if (sum > tab[i + 1].size || tab[i + 1].size == tab[i].size)
		{
			tab[i].sameAsNext = true;
		}


	}

	for (int i = n - 2; i > 0; i--)
	{
		if (tab[i].sameAsNext && res[tab[i + 1].id])
		{
			res[tab[i].id] = true;
		}
	}

	for (int i = 0; i < n; i++)
	{
		printf(res[i] ? "T" : "N");
	}

	return 0;
}