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
#include <bits/stdc++.h>
using namespace std;
#define N 500002
#define ff first
#define se second
int n;
long long b[N], sm, mn;
pair<long long, int> a[N];
int check(int idx)
{
    long long sum = a[idx].ff, tn = 1;
    for (int j = 0; j < n; ++j)
    {
        if (j == idx)
            continue;
        if (sum > a[j].first)
        {
            sum += a[j].first;
        }
        else
        {
            tn = 0;
            break;
        }
    }
    return tn;
}
int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
    {
        scanf("%lld", &a[i].ff);
        b[i] = a[i].first;
        a[i].second = i;
    }
    sort(a, a + n);
    int wyn = -1;
    int l = 0, r = n - 1;
    while (l <= r)
    {
        int mid = (l + r) / 2;
        if (check(mid))
        {
            r = mid - 1;
            wyn = mid;
        }
        else
        {
            l = mid + 1;
        }
    }
    if (wyn == -1)
        wyn = INT_MAX;
    else
        wyn = a[wyn].ff;
    for (int i = 0; i < n; ++i)
    {
        if (b[i] >= wyn)
            printf("T");
        else
            printf("N");
    }
}