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

#define ll long long

struct Fish {
  ll weight;
  int index;
  bool king;

  bool operator<(const Fish &fish) {
    return this->weight < fish.weight;
  }
};

vector<Fish> V;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll num;
  cin >> num;
  V.resize(num);

  for (ll i = 0; i < V.size(); i++) {
    cin >> V[i].weight;
    V[i].index = i;
  }
  sort(V.begin(), V.end());

  vector<ll> prefix_sum(V.size());
  prefix_sum[0] = V[0].weight;
  for (ll i = 1; i < prefix_sum.size(); i++) {
    prefix_sum[i] = prefix_sum[i - 1] + V[i].weight;
  }

  if (V.back().weight == V[0].weight) {
    for (int i = 0; i < V.size(); i++) {
      cout << "N";
    }
    return 0;
  } else {
    V.back().king = true;
  }

  for (int i = V.size() - 2; i > 0; i--) {
    if (V[i].weight > V[0].weight && prefix_sum[i] > V[i + 1].weight) {
      V[i].king = true;
    } else {
      break;
    }
  }

  vector<ll> res(V.size());
  for (ll i = 0; i < V.size(); i++) {
    res[V[i].index] = V[i].king;
  }
  for (auto const &fish : res) {
    cout << (fish ? "T" : "N");
  }
}