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 <iostream>
#include <set>
#include <utility>

namespace {
  using std::cin;
  using std::cout;
  using std::string;

  using weight_pos_t = std::pair<size_t, size_t>;
  using weight_pos_set_t = std::set<weight_pos_t>; 

  inline char const T_ANS = 'T';
  inline char const N_ANS = 'N';
  inline char const U_ANS = '?'; 
}

int main() {
  size_t n;
  size_t weight;
  weight_pos_set_t catfishes;
  size_t accum_weight = 0;  

  cin >> n;  

  for (size_t k = 0; k < n; ++k) {
    cin >> weight;
    accum_weight += weight;
    catfishes.insert({weight, k});
  }

  string answer(n, U_ANS);
  auto curr_weight_it = catfishes.rbegin();
  char last_ans = T_ANS;

  if (catfishes.rbegin()->first == catfishes.begin()->first &&
      catfishes.size() > 1)
    last_ans = N_ANS;

  for (auto it = catfishes.rbegin(); it != catfishes.rend(); ++it) {
    if (last_ans == T_ANS && it->first != curr_weight_it->first) {
      if (accum_weight > curr_weight_it->first &&
          it->first > catfishes.begin()->first)
        last_ans = T_ANS;
      else
        last_ans = N_ANS;
      curr_weight_it = it;
    }  
    answer.at(it->second) = last_ans;
    accum_weight -= it->first; 
  }

  cout << answer;

  return 0;
}