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
#include <stdio.h>
#include <stdlib.h>

struct entry {
	int size;
	int index;
};

struct entry entries[500000];
char answer[500001];

int cmp(const void *a, const void *b)
{
	struct entry *ea = (struct entry *)a;
	struct entry *eb = (struct entry *)b;

	return ea->size - eb->size;
}

int main(void)
{
	int n;
	int i;
	long long sum = 0;
	int limit;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &entries[i].size);
		entries[i].index = i;
	}
	qsort(entries, n, sizeof(entries[0]), cmp);

	limit = entries[0].size;
	for (i = 0; i < n - 1; i++) {
		sum += entries[i].size;
		if (sum <= entries[i+1].size)
			limit = entries[i].size;
	}
	for (i = 0; i < n; i++)
		answer[entries[i].index] = entries[i].size > limit ? 'T' : 'N';
	puts(answer);

	return 0;
}