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
#include <cstdio>
#include <algorithm>

using namespace std;

using ll = long long int;

const int MAXN = 500010;
pair<ll, int> tab[MAXN];
int n;
char out[MAXN];


bool test(int k) {
  ll sum = tab[k].first;
  for (int i = 0; i < n; i++) {
    if (i == k) continue;
    if (sum <= tab[i].first) return false;
    sum += tab[i].first;
  }

  return true;
}

void report(int k) {
  for (int i = 0; i < n; i++) {
    char c = i < k ? 'N' : 'T';
    out[tab[i].second] = c;
  }
  for (int i = 0; i < n; i++) printf("%c", out[i]);
  puts("");
  exit(0);
}


int main() {

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &tab[i].first);
    tab[i].second = i;
  }

  sort(tab, tab + n);
  if (test(0)) report(0);
  if (!test(n - 1)) report(n);

  int l = 0;
  int r = n;
  while (l < r) {
    int mid = (l + r) / 2;
    if (test(mid)) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  report(l);
}