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
#include <iostream>
#include <algorithm>
#include <vector>

typedef long long ll;

struct sum {
	int size;
	int index;
};

struct sum_sort {
	bool operator()(const sum& left, const sum& right) {
		return left.size < right.size;
	}
};

int main() {
	int n;
	std::cin >> n;
	bool* winner = new bool[n] {false};
	std::vector<sum> sumy;
	for (int i = 0; i < n; ++i) {
		sum s;
		std::cin >> s.size;
		s.index = i;
		sumy.push_back(s);
	}
	std::sort(sumy.begin(), sumy.end(), sum_sort());

	ll total_weight = sumy[0].size;
	int last_weight = sumy[0].size;
	int first_winner = n;
	int i = 1;
	for (; i < n; ++i) {
		total_weight += static_cast<ll>(sumy[i].size);
		if (last_weight < sumy[i].size) {
			last_weight = sumy[i].size;
			first_winner = i++;
			break;
		}
	}

	for (; i < n; ++i) {
		if (total_weight <= sumy[i].size) {
			first_winner = i;
		}

		total_weight += sumy[i].size;
	}

	for (i = first_winner; i < n; ++i) {
		winner[sumy[i].index] = true;
	}

	for (i = 0; i < n; ++i) {
		std::cout << (winner[i] ? 'T' : 'N');
	}
	std::cout << std::endl;

	return 0;
}