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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

long long int tab[500000];
long long int tab2[500000];

int main()
{
	long long int suma = 0;
	vector<long long int> sumy_init;
	vector<long long int> sumy;
	int n;
	cin >> n;
	long long int sum;
	for (int i = 0; i < n; i++) {
		cin >> sum;
		suma += sum;
		sumy.push_back(sum);
		sumy_init.push_back(sum);
	}
	if (n == 1) {
		cout << "T";
		return 0;
	}
	sort(sumy.begin(), sumy.end());
	//sumy.erase(unique(sumy.begin(), sumy.end()), sumy.end());
	//for (int i = 0; i < n; i++) {
	//	cout << sumy[i] << " ";
	//}
	//cout << "\n";
	tab[0] = sumy[0];
	tab2[0] = 0;
	int curr = sumy[0];
	for (int i = 1; i < n; i++) {
		tab[i] = tab[i - 1] + sumy[i];
		if (sumy[i] == curr) {
			tab2[i] = tab2[i - 1];
		}
		else {
			tab2[i] = tab[i - 1]; //+ sumy[i-1];
			curr = sumy[i];
		}
	}
	//for (int i = 0; i < n; i++) {
	//	cout << tab2[i] << " ";
	//}
	//cout << "\n";
	//for (int i = 0; i < n; i++) {
	//	cout << tab[i] << " ";
	//}
	//cout << "\n";
	if (tab2[n - 1] == 0) {
		for (int i = 0; i < n; i++) {
			cout << "N";
		}
	}
	else {
		int lowest = sumy[n - 1];
		for (int i = n - 2; i >= 0; i--) {
			if (tab2[i] + sumy[i] > sumy[i + 1]) {
				//cout << tab2[i] << " " << sumy[i] << " " << sumy[i + 1] << "\n";
				lowest = sumy[i];
			}
			else {
				lowest = sumy[i + 1];
				//cout << "what";
				break;
			}
		}
		//cout << lowest;
		for (int i = 0; i < n; i++) {
			if (sumy_init[i] >= lowest) {
				cout << "T";
			}
			else {
				cout << "N";
			}
		}
	}
	return 0;
}