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>
#define cerr if(0) cout
using namespace std;

int n;

bool ok(int x, vector <int>& v){
	long long size = v[x];
	int pos = 0;

	while(pos<n){
		if(v[pos] != v[x]){
			if(v[pos] < size){
				size += v[pos];
				cerr << "zjadamy rybke na pozycji: " << pos << ", akt suma: " << size << "\n";
			}else{
				cerr << "nie git\n";
				return false;
			}
		}else x = n;
		pos++;
	}

	cerr << "git\n";
	return true;
}

// 4 4 5

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin >> n;
	vector <int> fish(n), sfish(n+1);

	for(int i = 0; i<n; ++i){
		cin >> fish[i];
		sfish[i] = fish[i];
	}

	sort(sfish.begin(), sfish.begin()+n);
	sfish[n] = 1'000'000'003;

	int l = 0, p = n-1, s;
	while(l<p){
		s = (l+p)/2;
		cerr << s << "\n";
		if(ok(s, sfish)) p = s;
		else l = s+1;
		cerr << "\n";
	}

	if(l == n-1){
		if(!ok(l, sfish)) l++;
	}

	cerr << "l: " << l << "\n";
	for(auto& i: fish){
		if(i >= sfish[l]) cout << "T";
		else cout << "N";
	}

	cout << "\n";

}