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
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<pair<int, int> > v;
char r[500005];

int main()
{
    int n;
    cin >> n;
    v.resize(n);
    int a;
    for (int i=0;i<n;i++)
    {
        scanf("%d",&a);
        v[i] = make_pair(a,i);
    }
    sort(v.begin(), v.end());
    long long s = 0;
    int mn = -1;
    if (v[0].first == v[n-1].first) mn = n - 1;
    else
    {
        for (int i=0;i<n-1;i++)
        {
            s += v[i].first;
            if (v[0].first == v[i].first || s <= v[i+1].first) mn = i;
        }
    }

    for (int i=0;i<=mn;i++) r[v[i].second] = 'N';
    for (int i=mn+1;i<n;i++) r[v[i].second] = 'T';
    r[n]=0;
    cout << r << endl;
}