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

int main() {

long long int n, a, min=1000000000, w=0;
cin >> n;
vector < pair < long long int,long long int> > vec;
vector < long long int > pom;
long long int tab[n+5];
for(long long int i=0; i<n; i++)
{
	cin >> tab[i];
	if(tab[i]<min)
	min=tab[i];
	vec.push_back(make_pair(tab[i], i));
}
sort(vec.begin(), vec.end());
for(long long int i=1; i<n; i++)
{
	pom.push_back(vec[i].first);
	if((tab[vec[i].second] == tab[vec[i-1].second]) && vec[i].first>min)
	{
		vec[i].first += vec[i-1].first;
		w+= vec[i-1].first;
	}
	else
	{
		if(vec[i].first > vec[i-1].first-w)
		vec[i].first += vec[i-1].first;
		w+= vec[i-1].first;
	}
}

for(long long int i=0; i<pom.size(); i++)
	vec[i+1].second = pom[i];
	
a=1000000005;
for(long long int i=n-1; vec[i].first>0; i--)
{
	if(vec[i].first < vec[i+1].second && i!=n-1)
	{
		a=vec[i].second;
		break;
	}
}
for(long long int i=0; i<n; i++)
{
	if(tab[i]>a)
	cout << "T";
	else
	cout << "N";
}
	return 0;
}