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
74
75
76
//author Karolina Miśkiewicz
#include<bits/stdc++.h>
using namespace std;
int tab[500007];

struct fish
{
    int w;
    int nr;

    bool operator<(const fish &o) const
    {
        return w < o.w;
    }
};

int main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    vector<fish> v;
    int n,max = 0, min = 1000000000 + 11;
    long long all = 0;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        int a; 
        cin >> a;
        all += a;
        if(a < min)
            min = a;
        if(a > max)
            max = a;
        v.push_back({a,i});
    }

    sort(v.begin(),v.end());
    if(max != min)
    {
    	int pop = max;
        while(v[v.size()-1].w == max)
        {
           tab[v[v.size()-1].nr] = 1;
           all -= max;
           v.pop_back();
        }
        while(v[v.size()-1].w > min)
        {
            if(all > pop)
            {
                int temp = v[v.size()-1].w;
                while(v[v.size()-1].w == temp)
                {
                    tab[v[v.size()-1].nr] = 1;
                    all -= temp;
                    v.pop_back();
                }
                pop = temp;
            }
            else
                break;
        }
    }



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