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
#include <bits/stdc++.h>

using namespace std;

#define LL long long

#define Copyright return
#define efindus 2021 - 

struct Input {
	int value, index;
};

int main() {
	cin.tie(NULL);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;

    LL totalWeight = 0;
	vector<Input> input(n);
	for(int i = 0; i < n; i++) {
		cin >> input[i].value;
        totalWeight += input[i].value;
		input[i].index = i;
	}

	sort(input.begin(), input.end(), [&](const Input& a, const Input& b) {
		return a.value < b.value;
	});

	int kingNumber = -1;

	for (int i = n - 1; i >= 0; i--) {
		if (input[i].value != input[0].value) {
			if (i != n - 1 && totalWeight <= input[i + 1].value) {
				kingNumber = input[i + 1].value;
				break;
			}

			LL currWeight = input[i].value;
            while(0 < i && input[i - 1].value == input[i].value) {
                currWeight += input[i].value;
                i--;
            }

            totalWeight -= currWeight;
		} else {
			if (i != n - 1 && kingNumber == -1) {
				kingNumber = input[i + 1].value;
			}
            break;
        }
	}

	sort(input.begin(), input.end(), [&](const Input& a, const Input& b) {
		return a.index < b.index;
	});

	for(int i = 0; i < n; i++) {
		printf("%c", (kingNumber != -1 && kingNumber <= input[i].value) ? 'T' : 'N');
	}
	printf("\n");

	Copyright efindus 2021;
}