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

using namespace std;

int main() {

	std::ios_base::sync_with_stdio(false);

	std::cin.tie(NULL);

	int n;
	cin >> n;

	vector<int> ryby(n, 0);
	vector<char> answer(n, 'N');

	unordered_multimap<int, size_t> map(n);
	int waga;
	for (int i = 0; i < n; i++) {
		cin >> waga;
		ryby[i] = waga;
		map.insert({waga, i});
	}
	sort(ryby.begin(), ryby.end());
	int sum = 0;
	int last = 0;
	int i = 1;
	sum+=ryby[0];
	while (i  < n && ryby[i-1] == ryby[i]) {
		sum += ryby[i];
		last = i +1;
		i++;
	}

	for (i ; i < n; i++) {
		if (sum <= ryby[i]) {
			last = i;

		}
		sum += ryby[i];

	}
	for (int i = n - 1; i >= last; i--) {
		auto it = map.find(ryby[i]);
		answer[it->second] = 'T';
		map.erase(it);
	}

	for (int i = 0; i < n; i++) {
		cout << answer[i];
	}

}
/*
 *
 *6 2 7 1 8 2 8
 */