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
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <bitset>
using namespace std;
int n;
long long a, px[500005];
vector<pair<long long, int>> v;
bitset<500001> bs, wyn;
int main()
{
    scanf("%d", &n);
    for(int i = 0; i < n; ++i){
            scanf("%lld", &a);
            v.push_back(make_pair(a,i));
    }

    sort(v.begin(), v.end());

    bs.flip(0);

    for(int i = 1; i < n; ++i){
            px[i] = px[i-1] + v[i-1].first;
            if(v[i-1].first == v[i].first && bs.test(i-1)) bs.flip(i);
    }

    if(!bs.test(n-1)){
            wyn.flip(v.back().second);
            for(int i = n-2; i >= 1; --i){
                    if(bs.test(i)) break;
                    if(px[i] + v[i].first > v[i+1].first) wyn.flip(v[i].second);
                    else break;
            }
    }

    for(int i = 0; i < n; ++i){
            if(wyn.test(i)) printf("T");
            else printf("N");
    }
    
    return 0;
}