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
#include <bits/stdc++.h>
using namespace std;
int n, a[500005], b[500005];
long long dp[500005];
bitset <1000000005> taknie;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> n;

    for(int i = 1; i<=n; ++i)
    {
        cin >> a[i];

        b[i] = a[i];
    }

    sort(a, a+n+1);

    for(int i = 1; i<=n; ++i)
    {
        dp[i] = dp[i-1] + a[i];
    }

    if(a[n]!=a[1])
        taknie[a[n]]=1;

    for(int i = n-1; i>=2; --i)
    {
        if(taknie[a[i+1]] && dp[i]>a[i+1] && a[i]!=a[1])
        {
            taknie[a[i]]=1;
            //cout << a[i];
        }
    }

    for(int i = 1; i<=n; ++i)
    {
        if(taknie[b[i]])
        {
            cout << "T";
        }
        else
        {
            cout << "N";
        }
    }

    return 0;
}