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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include "bits/stdc++.h"

using namespace std;

using pi = pair<int, int>;
using vpi = vector<pi>;
using vi = vector<int>;
using mib = map<int, bool>;


int main() {
    int n;
    cin >> n;
    vi catfish;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        catfish.push_back(x);
    }

    mib can_eat_next;
    vi orig_catfish(catfish);
    sort(catfish.begin(), catfish.end());

    int64_t total_mass_of_smaller = 0;
    bool is_first = true;
    int i = 0;
    while(i < n) {
        int current_mass = catfish[i];
        int64_t total_mass_of_equal = catfish[i];
        while(i < n - 1 && (i == n-1 || catfish[i] == catfish[i+1])) {
            total_mass_of_equal += catfish[i];
            i++;
        }
        if(i == n) {
            i -= 1;
        }

        int64_t available_mass = total_mass_of_smaller + current_mass;
        if(!is_first)  {
            available_mass += total_mass_of_equal - current_mass;
        }

        if((i == n - 1 && !is_first) || (i != n - 1 && available_mass > catfish[i+1] )) {
            can_eat_next[catfish[i]] = true;
        }
        else {can_eat_next[catfish[i]] = false;}
        is_first = false;
        total_mass_of_smaller += total_mass_of_equal;
        i++;
    }

    mib can_become_king;
    for(auto it = can_eat_next.rbegin(); it != can_eat_next.rend() ; ++it) {
        auto [mass, res] = *it;
        if(res) {
            can_become_king[mass] = true;
        }
        else {
            break;
        }
    }

    for(auto el: orig_catfish) {
        if(can_become_king.find(el) != can_become_king.end()) {
            cout << "T";
        }
        else {
            cout << "N";
        }
    }



    return 0;
}