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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#ifdef LOCAL
#define debug(...) __VA_ARGS__
#else
#define debug(...) {}
#endif
const ll INF = 1e18;
bool wy[500005];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int i;
    int n;
    cin>>n;
    pair<ll,ll> tab[n+1];
    for (i = 0; i < n ; i++){
        cin>>tab[i].first;
        tab[i].second = i;
    }
    stable_sort(tab,tab+n);
    tab[n] = {INF,n};
    ll suma = 0;
    ll aktsuma = 0;
    bool pierwsza = 1;
    ll pop = tab[0].first;
    vector<int> good;
    for (i = 0; i < n+1 ; i++){
        if (tab[i].first != pop){
            suma += aktsuma;
            aktsuma = 0;
            pierwsza = 0;
            pop = tab[i].first;
            if (tab[i].first >= suma && i != n) good.clear();
        }
        aktsuma += tab[i].first;
        if (!pierwsza) good.push_back(tab[i].second);;
    }
    for (int j : good) wy[j] = 1;
    for (i = 0; i < n ; i++){
        if (wy[i]) cout<<"T";
        else cout<<"N";
    }
    cout<<"\n";
    return 0;
}