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

int main() {
	int n;
	std::cin >> n;

	std::vector<int> weights(n);
	for (int i = 0; i < n; i++) {
		std::cin >> weights[i];
	}

	std::vector<int> sorted;
	copy(weights.begin(), weights.end(), back_inserter(sorted));
	std::sort(sorted.begin(), sorted.end());

	std::vector<long long> sums(n);
	sums[0] = sorted[0];
	for (int i = 1 ; i < n; i++) {
		sums[i] = sums[i - 1] + sorted[i];
	}

	sorted.push_back(sorted.back());
	std::map<int, bool> possible;
	for (int i = n - 1; i >= 1; --i) {
		if (sorted[i] + sums[i - 1] > sorted[i + 1] && sorted[i] != sums[i - 1] / i) {
			possible[sorted[i]] = true;
		} else {
			break;
		}
	}

	std::string result = "";
	for (auto w: weights) {
		result += (possible[w] ? "T" : "N");
	}
	std::cout << result << '\n';
	return 0;
}