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, poz, licz;
long long tab1[500007];
pair<int, int> tab[500007];
set<int> s;
bool cmp(const pair<int, int> &a, const pair<int, int> &b)
{
    if(a.second < b.second)
        return 1;
    return 0;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i = 1;i<=n;i++)
    {
        cin>>a;
        tab[i] = {a, i};
    }
    sort(tab+1, tab+n+1);

    for(int i = 1;i<=n and poz==0;i++)
    {
        tab1[i] = tab1[i-1];
        if(tab[i].first>tab[i-1].first)
        {
            tab1[i]+=tab[i].first;
            tab1[i]+=(licz)*tab[i-1].first;
            licz = 0;
        }
        else
            licz++;
    }
    int x = n-1;
    while(tab1[x]>tab[x+1].first)
        x--;
    poz = tab[x+1].first;

    sort(tab+1, tab+n+1, cmp);

    //cout<<poz<<"\n";
    for(int i = 1;i<=n;i++)
        if(tab[i].first>=poz)
            cout<<"T";
        else
            cout<<"N";

    return 0;
}