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

int n;
std::vector<std::pair<long long, int>> fishes;

bool canFishSucceed(int fish)
{
    long long sum = fishes[fish].first;
    for (int i = 0; i < n; i++)
    {
        if (i == fish)
            continue;
        if (sum <= fishes[i].first)
            return false;
        sum += fishes[i].first;
    }
    return true;
}

int main()
{
    scanf("%d", &n);
    fishes.resize(n);
    for (int i = 0; i < n; i++)
    {
        long long fish;
        scanf("%lld", &fish);
        fishes[i] = {fish, i};
    }
    std::sort(fishes.begin(), fishes.end());
    int l = 0;
    int r = n;
    while (l < r)
    {
        int s = (l + r) / 2;
        if(canFishSucceed(s))
        {
            r = s;
        }
        else
        {
            l = s + 1;
        }
    }
    std::vector<bool> can_fish_succeed;
    can_fish_succeed.assign(n, false);
    for (int i = l; i < n; i++)
    {
        can_fish_succeed[fishes[i].second] = true;
    }
    for (int i = 0; i < n; i++)
    {
        if (can_fish_succeed[i])
            printf("T");
        else
            printf("N");
    }
    printf("\n");
}