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
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int fish[n], fishSorted[n];
  for (int i = 0; i < n; i++) {
    cin >> fish[i];
    fishSorted[i] = fish[i];
  }
  sort(fishSorted, fishSorted + n);
  int smallestFishSize = fishSorted[0], smallestFishCount = 0, fishKingSize = 0;
  while (smallestFishCount < n &&
         fishSorted[smallestFishCount] == smallestFishSize)
    smallestFishCount++;
  if (smallestFishCount == n)
    fishKingSize = smallestFishSize + 1;
  else {
    long long smallerFishTotalSize = smallestFishSize * smallestFishCount;
    int currentFishSize = fishSorted[smallestFishCount];
    for (int i = smallestFishCount + 1; i < n; i++) {
      if (currentFishSize + smallerFishTotalSize > fishSorted[i])
        smallerFishTotalSize += fishSorted[i];
      else {
        smallerFishTotalSize += currentFishSize;
        currentFishSize = fishSorted[i];
      }
    }
    fishKingSize = currentFishSize;
  }
  for (int i = 0; i < n; i++) {
    if (fish[i] >= fishKingSize)
      cout << 'T';
    else
      cout << 'N';
  }
  cout << endl;
  return 0;
}