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

typedef long long ll;
using namespace std;

struct Sum {
    int index;
    ll size;
    
    bool operator<(const Sum& other) const {
        if(size == other.size) return index < other.index;
        return size < other.size;
    }
};

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin>>n;
    vector<Sum> sums(n);
    for(int i = 0; i < n; ++i) {
        cin>>sums[i].size; sums[i].index = i;
    }
    sort(sums.begin(), sums.end());

    vector<ll> prefix(n + 1);
    prefix[0] = 0;
    for(int i = 1; i <= n; ++i) {
        prefix[i] = prefix[i - 1] + sums[i - 1].size;
    }

    int last_cliff = 1;
    for(int i = 1; i < n; ++i) { // 4 4 4 4 4 5 (all fours at the start can't eat each other)
        if(sums[i].size == sums[0].size) {
            last_cliff = i + 1;
        }else {
            break;
        }
    }
    for(int i = last_cliff; i < n; ++i) {
        if(prefix[i] <= sums[i].size) {
            last_cliff = i;
        }
    }

    vector<bool> king(n, false);
    for(int i = 0; i < n; ++i) {
        if(i < last_cliff) {
            king[sums[i].index] = false;
        }else {
            king[sums[i].index] = true;
        }
    }

    for(int i = 0; i < n; ++i) {
        if(king[i]) {
            cout<<"T";
        }else {
            cout<<"N";
        }
    }
}