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
#include <iostream>
#include <algorithm>
int n;
long long v;
std::pair<long long,int> ctfsh[500000];
long long sum = 0;

int main()
{
	std::ios_base::sync_with_stdio(false);
	std::cin >> n;
	std::string res(n,'N');
	for( int i = 0; i < n; i++ )
	{
		std::cin >> v;
		ctfsh[i] = std::make_pair(v,i);
		sum += v;
	}
	std::sort(ctfsh,ctfsh + n);
	res[ctfsh[n-1].second] = 'T';
	sum -= ctfsh[n-1].first;
	int i = n-2;
	for( ; i >= 0; i-- )
	{
		if( sum > ctfsh[i+1].first )	res[ctfsh[i].second] = 'T';
		else break;
		sum -= ctfsh[i].first;
	}
	while( i < n-1 && ctfsh[i+1].first == ctfsh[i].first )
	{
		i++;
		res[ctfsh[i].second] = 'N';
	}
	std::cout << res << '\n';
	return 0;
}