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

using namespace std;

using ll = long long;

#define MAX_N 500007

int n;
int psearch, ssearch, msearch;
ll sum_jeden;
pair <ll, int> potezny_sum[MAX_N];
bool resTab[MAX_N];

bool git_sum(int idx) {
  ll curWeight = potezny_sum[idx].first;
  for (int i = 1; i <= n; i++) {
    if (idx == i) continue;
    if (curWeight <= potezny_sum[i].first) {
      return false;
    }
    else {
      curWeight += potezny_sum[i].first;
    }
  }
  return true;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  
  cin >> n;
  
  for (int i = 1; i <= n; i++) {
    cin >> sum_jeden;
    potezny_sum[i] = make_pair(sum_jeden, i);
  }
  
  sort(potezny_sum + 1, potezny_sum + n + 1);

  psearch = 1;
  ssearch = n + 1;

  while (psearch < ssearch) {

    msearch = (psearch + ssearch) / 2;
    if (git_sum(msearch)) {
      ssearch = msearch;
    }
    else {
      psearch = msearch + 1;
    }
  }
  for (int i = psearch; i <= n; i++) {
    resTab[potezny_sum[i].second] = true;
  }

  for (int i = 1; i <= n; i++) {
    resTab[i] ? cout << "T" : cout << "N";
  }
}