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

typedef long long int LL;

const int MAX_N = 500005;

int n, nums[MAX_N], sortedNums[MAX_N];
LL overallSum;
map<LL, LL> counts, sums;

bool check(const int idx)
{
    LL actSum = sortedNums[idx];
    for(int i = 0; i < n; ++i)
    {
        if(i == idx)
        {
            continue;
        }

        if(actSum > sortedNums[i])
        {
            actSum += sortedNums[i];
        }
        else
        {
            return false;
        }
    }
    return true;
}


int minKingWeight()
{
    int left = 0, right = n-1, resIdx = -1;
    while(left <= right)
    {
        const int mid = (left+right)/2;
        if(!check(mid))
        {
            left = mid+1;
        }
        else
        {
            resIdx = mid;
            right = mid-1;
        }
    }

    return resIdx == -1
        ? sortedNums[n-1]+1
        : sortedNums[resIdx];
}

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> n;
    for(int i = 0; i < n; ++i)
    {
        cin >> nums[i];
        sortedNums[i] = nums[i];
    }

    sort(sortedNums, sortedNums+n);

    const int minKing = minKingWeight();
    for(int i = 0; i < n; ++i)
    {
        cout << (nums[i] >= minKing ? 'T' : 'N');
    }
    cout << endl;

    return 0;
}