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
#include <bits/stdc++.h>
using namespace std;
const int N = 500001;
int n, t[N];
long long pref[N], mn;
vector<int>v;

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

  cin >> n;

  for(int i = 0; i < n; i++) {
    cin >> t[i];
    v.push_back(t[i]);
  }

  sort(v.begin(), v.end());

  pref[0] = v[0];
  for (int i = 0; i < v.size(); i++) {
    pref[i] = pref[i - 1] + v[i];
  }

  for (int i = n - 1; i >= 0; i--) {
    if (v[i] != v[i - 1]) {
      if (pref[i - 1] <= v[i]) {
        mn = v[i];
        break;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    if (t[i] >= mn && t[i] > v[0]) {
      cout << "T";
    } else {
      cout << "N";
    }
  }

  cout << endl;

  return 0;
}