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
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> > V;
vector<bool> CC;
int main()
{
    ios_base::sync_with_stdio(0);
    int n,a;
    long long suma=0;
    cin>>n;
    CC.resize(n+1,0);
    for(int i=0;i<n;i++)
    {
        cin>>a;
        V.push_back({a,i});
        suma += (long long)a;
    }
    sort(V.begin(),V.end());
    CC[V[n-1].second] = 1;
    suma -= V[n-1].first;
    bool koniec = 0;
    for(int i=n-2;i>=0;i--)
    {
        if(koniec) CC[V[i].second]=0;
        else if(V[i].first == V[i+1].first)
        {
            CC[V[i].second] = CC[V[i+1].second];
        }
        else
        {
            if(suma > V[i+1].first) CC[V[i].second]=1;
            else
            {
                CC[V[i].second]=0;
                koniec=1;
            }
        }
        suma -= V[i].first;
    }
    CC[V[0].second] = 0;
    for(int i=1;i<n;i++)
    {
        if(V[i-1].first == V[i].first) CC[V[i].second]=0;
        else break;
    }
    for(int i=0;i<n;i++)
    {
        if(CC[i]==1) cout<<"T";
        else cout<<"N";
    }
    cout<<"\n";
}