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;

bool operator<(pair<long long,int> x, pair<long long,int> y)
{
    if(y.first>=x.first) return true;
    return false;
}

long long sprawdzanie(vector<pair<long long,int>> const &v, int c1, int c2)
{
    if(c1==c2)
    {
        return v[c2].first;
    }
    int sr=c1+(c2-c1)/2;
    long long s=v[sr].first;
    int o=0;
    bool e=true;
    while(o<v.size()&&e==true)
    {
        if(v[o].second==sr)
        {
            o++;
        }
        if(s>v[o].first)
        {
            s+=v[o].first;
        }
        else
        {
            e=false;
        }
        o++;
    }
    if(e==true)
    {
        return sprawdzanie(v,c1,sr);
    }
    else
    {
        return sprawdzanie (v,sr+1,c2);
    }
}

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<long long> sumy;
    vector<pair<long long,int>> wagi;
    for(int o=0;o<n;o++)
    {
        long long w;
        cin>>w;
        sumy.push_back(w);
        wagi.push_back(make_pair(w,o));
    }
    sort(wagi.begin(),wagi.end());
    long long x=sprawdzanie(wagi,0,(n-1));
    for(int o=0;o<n;o++)
    {
        if(sumy[o]>=x)
        {
            cout<<"T";
        }
        else
        {
            cout<<"N";
        }
    }
}