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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define st first
#define nd second
int n;
pair <ll, int> a[500005];
char res[500005];
ll sum[500005];

bool dasie (int x)
{
    if (x==0)
        return false;
    if (a[x].st==a[0].st)
        return false;
    //cout<< x<< ' '<< a[x].st<< "  ";
    for (int i=x; i<n; i++)
    {
        if (sum[i]<=a[i+1].st)
            return false;
    }
    return true;
}

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

    cin>> n;
    for (int i=0; i<n; i++)
    {
        cin>> a[i].st;
        a[i].nd=i;
    }
    sort (a,a+n);

    sum[0]=a[0].st;
    for (int i=1; i<n; i++)
        sum[i]=sum[i-1]+a[i].st;

    /*res[a[0].nd]='N';
    int i=1;
    while (i<n && a[i-1]==a[i])
    {
        res[a[i].nd]='N';
        i++;
    }*/

    int l=0, r=n-1, m;
    while (l<r)
    {
        m=(l+r+1)/2;
        //cout<< dasie(m)<< '\n';
        if (dasie(m))
            r=m-1;
        else
            l=m;
    }

    for (int i=0; i<=l; i++)
        res[a[i].nd]='N';
    for (int i=l+1; i<n; i++)
        res[a[i].nd]='T';

    for (int i=0; i<n; i++)
        cout<< res[i];


        return 0;
}