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

int n;
ll t[500001];
ll ts[500001];

bool check(int x)
{
    ll wiel = ts[x];
    for(int i=0; i<n; ++i)
    {
        if(x == i)
            continue;
        //printf("%d ", wiel);
        if(wiel <= ts[i])
            return false;
        wiel += ts[i];
        wiel = min(1000000007ll, wiel);
    }
    return true;
}

int main()
{
    scanf("%d", &n);
    for(int i=0; i^n; ++i)
    {
        scanf("%lld", &t[i]);
        ts[i] = t[i];
    }
    sort(ts, ts+n);
    ts[n] = INT32_MAX;

    int p = 0, k = n, w = -1;
    while(p <= k)
    {
        int mid = (p+k)/2;
        //printf("\n%d\n", mid);
        if(check(mid))
        {
            w = mid;
            k = mid-1;
        }
        else
        {
            p = mid+1;
        }
    }

    for(int i=0; i^n; ++i)
    {
        if(w != -1 && t[i] >= ts[w])
            printf("T");
        else
            printf("N");
    }
    printf("\n");
}