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 <bits/stdc++.h>
using namespace std;

bool can_be_king(const vector<pair<long long, int>> &fishes, int fish_index)
{
    long long fish_size = fishes[fish_index].first;
    int i = 0;
    while (i < (int) fishes.size() && fishes[i].first < fish_size) {
        if (i != fish_index) {
            fish_size += fishes[i].first;
        }
        ++i;
    }
    return i == (int) fishes.size();
}

int main()
{
    int n;
    cin >> n;
    vector<pair<long long, int>> fishes(n);
    for (int i = 0; i < n; ++i) {
        cin >> fishes[i].first;
        fishes[i].second = i;
    }
    sort(fishes.begin(), fishes.end());
    int left = 0, right = fishes.size();
    while (left + 1 < right) {
        int middle = (left + right) / 2;
        if (can_be_king(fishes, middle)) {
            right = middle;
        } else {
            left = middle;
        }
    }
    string answer(n, 'N');
    for (int i = right; i < n; ++i) {
        answer[fishes[i].second] = 'T';
    }
    cout << answer << endl;
    return 0;
}