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

unsigned long long chains[500000] = { 0 };

void display(int a, std::vector<int>& sums) {
	for (int i : sums) {
		(i >= a) ? std::cout << "T" : std::cout << "N";
	}
}

int main() {
	std::ios::sync_with_stdio(false);
	int n;
	int weight;
	std::vector<int> sums;
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> weight;
		sums.push_back(weight);
	}
	std::vector<int> temp = sums;
	std::sort(temp.begin(), temp.end());
	size_t size = temp.size();
	unsigned long long w = temp.at(0);
	unsigned long long buffer = 0;
	chains[0] = temp.at(0);
	for (int i = 1; i < size; i++) {
		if (chains[i - 1] > temp.at(i)) {
			w += temp.at(i) + buffer;
			buffer = 0;
		}
		else if (temp.at(i) > temp.at(i - 1)) {
			w += temp.at(i) + buffer;
			buffer = 0;
		}
		else
			buffer += temp.at(i);

		chains[i] = w;
	}
	int end = temp.at(size - 1);
	for (int i = 0; i < size - 1; i++) {
		if (chains[i] > temp.at(i + 1)) {
			if (end == temp.at(size - 1))
				end = temp.at(i);
		}
		else
			end = temp.at(size - 1);
	}
	if (end == temp.at(0))
		end = 0x7fffffff;
	display(end, sums);
	return 0;
}