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

using namespace std;

#define ULL unsigned long long

int n;
vector<ULL> masses[2];

int main() {

   ios_base::sync_with_stdio(0);
   cin >> n;
   masses[0].reserve(n + 2);
   masses[1].reserve(n + 2);
   for(int i = 0; i < n; i++) {
      ULL mass;
      cin >> mass;
      masses[0].push_back(mass);
      masses[1].push_back(mass);
   }

   sort(masses[0].begin(), masses[0].end());

   ULL too_small = masses[0][0];

   int eaten = 0;
   ULL mass = too_small;
   
   for(int i = 1; i < n; i++) {
      if(masses[0][i] == too_small) {
         eaten++;
         mass += too_small;
      }
   }

   for(int i = eaten + 1; i < n; i++) {
      
      if(mass <= masses[0][i]) {
         too_small = masses[0][i - 1];
      }
      
      mass += masses[0][i];
      eaten++; 
   }

   for(int i = 0; i < n; i++) {
      cout << ((masses[1][i] > too_small) ? 'T' : 'N');       
   }
   cout << endl;
}