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

int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i=0; i<n; ++i)
    cin >> a[i];
  vector<int> b = a;
  sort(b.begin(), b.end());
  int l = 0, r = n;
  while (l < r) {
    int m = (l + r) / 2;
    int cur = b[m];
    bool done = false;
    for (int i = 0; i < n; ++i) {
      if (i != m) {
        if (b[i] >= cur)
          break;
        cur += b[i];
        if (cur > b.back()) {
          done = true;
          break;
        }
      }
    }
    // cerr << m << ' ' << b[m] << ' ' << done << endl;
    if (done)
      r = m;
    else
      l = m + 1;
  }
  int t = l < n ? b[l] : b.back() + 1;
  for (int i = 0; i < n; ++i)
    cout << (a[i] >= t ? 'T' : 'N');
  cout << endl;
}