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
#include <algorithm>
#include <iostream>
using namespace std;

const int MAXN = 500000;
const int INF = 2000000000;

#define FOR(i, n) for(int i = 0, __n = (n); i < __n; i++)


int a[MAXN];
int b[MAXN];
char K[MAXN+1];

int main() {
  ios_base::sync_with_stdio(0);

  int n; cin >> n;
  FOR(i, n) {
    cin >> a[i];
  }
  copy(a, a+n, b);

  sort(b, b+n);

  int i = 0;
  long long suma = 0;
  int thresh = INF;

  while(i < n) {

    suma += b[i];
    // cerr << "> " << i << " " << suma << endl;
    int j = i;
    while (j + 1 < n && suma > b[j + 1]) {
      j++;
      suma += b[j];
    }

    if(j == n - 1) {
      // cerr << ">> " << j << " " << suma << endl;
      thresh = b[i];
    }

    i = j + 1;
    while(i < n && b[i-1] == b[i]) {
      suma += b[i];
      i++;
    }
  }
  FOR(i, n) {
    if(a[i] >= thresh) K[i] = 'T';
    else K[i] = 'N';
  }
  cout << K << endl;
}