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
#include <cstdio>
#include <algorithm>
#include <vector>
#define MAKS 500010
#define f first
#define s second
#define mp make_pair
using namespace std;
typedef pair<int,int> para;
typedef long long int lld;
bool wyn[MAKS];
bool ok[MAKS];
int naj[MAKS];
int main()
{
    int n;
    scanf("%d",&n);
    vector<para> v;
    for(int i=0;i<n;i++)
    {
        int x;
        scanf("%d",&x);
        v.push_back(mp(x,i));
    }
    sort(v.begin(),v.end());
    lld s=0;
    int p=0;
    for(int i=0;i<v.size();i++)
    {
        s+=v[i].first;
        while(p<v.size() && lld(v[p].first)<s)p++;
        naj[i]=p;
    }
    for(int i=v.size()-1;i>=0;i--)
    {
        if(naj[i]==v.size() || (naj[i]-1>=0 && ok[naj[i]-1]))ok[i]=true;
    }
    for(int i=0;i<v.size();i++)
    {
        if(i>0 && v[i].first==v[i-1].first)
        {
            wyn[v[i].second]=wyn[v[i-1].second];
            continue;
        }
        if(ok[i])wyn[v[i].second]=true;
    }

    for(int i=0;i<n;i++)printf("%c",(wyn[i]?'T':'N'));
    puts("");
}