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

int main() {
   // freopen("pan0.in", "r", stdin);
   ios_base::sync_with_stdio(0);
   cin.tie(0);

   int n;
   cin >> n;
   vector<int> tab(n);
   for (auto& a : tab) {
      cin >> a;
   }

   vector<int> tab_org(tab);
   sort(tab.begin(), tab.end());

   // smallest can never win
   int rejected_size = tab[0];
   int64_t sum_so_far = tab[0];
   for (int i = 1; i < tab.size(); i++) {
      auto& a = tab[i];
      if (a == rejected_size || a >= sum_so_far) {
         rejected_size = tab[i - 1];
      }
      sum_so_far += a;
   }

   for (auto& a : tab_org) {
      cout << (a <= rejected_size ? "N" : "T");
   }
}