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
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

#define MAX_N	500010
#define MAX_A	1000000000LL

int N;

map<int, vector<int>> f;
char s[MAX_N];
int a;
long long w;

int main() {
	scanf("%d", &N);
	memset(s, 'T', N);

	for (int i = 0; i < N; ++i) {
		scanf("%d", &a);
		f[a].push_back(i);
	}

	a = 0;
	w = 0LL;
	for (auto it = f.begin(), itn = next(it); w <= MAX_A && itn != f.end(); it++, itn++) {
		w += 1LL * it->first * it->second.size();
		if (w <= 1LL * itn->first) {
			a = it->first;
		}
	}

	auto it = f.begin();
	if (a == 0) {
		a = it->first;
	}
	while (it != f.end() && it->first <= a) {
		for (auto itp = it->second.begin(); itp != it->second.end(); itp++) {
			s[*itp] = 'N';
		}
		it++;
	}

	printf("%s\n", s);
	return 0;
}