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
#include <iostream>
#include <algorithm>
using namespace std;

const int MAXN = 500000 + 7;
int inputTab[MAXN];
int tab[MAXN];

bool check(int n, int x, int id)
{
    long long sum = x;
    for(int i = 0; i < n; i++)
    {
        if(i == id) continue;
        if(sum <= (long long)tab[i]) return false;
        sum += (long long)tab[i];
    }
    return true;
}

int binsearch(int l, int p, int n)
{
    int sr;
    while(l < p)
    {
        sr = (l + p) / 2;
        if(check(n, tab[sr], sr)) p = sr;
        else l = sr + 1;
    }
    return p;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin>>n;
    for(int i = 0; i < n; i++) cin>>inputTab[i];
    copy(inputTab, inputTab + n, tab);
    sort(tab, tab + n);
    int pivot = INT32_MAX;
    if(tab[0] != tab[n - 1]) pivot = tab[binsearch(0, n - 1, n)];
    for(int i = 0; i < n; i++)
    {
        if(inputTab[i] >= pivot) cout<<'T';
        else cout<<'N';
    }
    cout<<'\n';
    return 0;
}