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

using ll = long long;

int main() {
  int n;
  scanf("%d", &n);
  vector<pair<ll, int>> v(n);
  for (int i = 0; i < n; i++) {
    v[i].second = i;
    scanf("%lld", &v[i].first);
  }
  sort(v.begin(), v.end());
  if (v[0].first == v.back().first) {
    if (n == 1) {
      printf("T\n");
    } else {
      printf("%s\n", string(n, 'N').c_str());
    }
    return 0;
  }
  int lo = -1, hi = n - 1;
  while (lo + 1 < hi) {
    int mid = (lo + hi) / 2;
    if (v[0].first == v[mid].first) {
      lo = mid;
      continue;
    }
    ll s = 0;
    for (int i = 0; i <= mid; i++) {
      s += v[i].first;
    }
    bool ok = true;
    for (int i = mid + 1; i < n; i++) {
      if (v[i].first >= s) {
        ok = false;
        break;
      }
      s += v[i].first;
    }
    if (ok) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  string res(n, 'N');
  for (int i = hi; i < n; i++) {
    res[v[i].second] = 'T';
  }
  printf("%s\n", res.c_str());
}