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
#include <bits/stdc++.h>
using namespace std;

pair<int, int> ry[500005];
bool ps[500005];

long long sm[500005], su[500005];

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> ry[i].first;
        ry[i].second = i;
    }
    sort(ry, ry + n);
    for (int i = 0; i < n; i++)
    {
        sm[i] += ry[i].first;
        sm[i + 1] = sm[i];
    }
    for (int i = n - 1; i >= 0; i--)
    {
        su[i] = max((long long)ry[i].first, su[i + 1] - ry[i].first);
        if ((ry[i].first != ry[0].first) && (sm[i] > su[i + 1]))
        {
            ps[ry[i].second] = 1;
        }
    }
    for (int i = 0; i < n; i++)
    {
        cout << ((ps[i]) ? 'T' : 'N');
    }
}