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

using namespace std;

const int N = 500'007;

int n, a[N], ii[N];

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);

    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i], ii[i] = i;

    sort(ii, ii + n, [](int x, int y) { return a[x] < a[y]; });

    int l = 0, r = n;

    while(r - l > 1) {

        int m = (l + r) >> 1;

        long long sum = a[ii[m]];
        bool ok = true;

        for(int i = 0; i < n; i++) if(i != m) {
            if(sum <= a[ii[i]]) {
                ok = false;
                break;
            }
            
            sum += a[ii[i]];
        }

        if(ok)  r = m;
        else    l = m;

    }

    for(int i = 0; i < n; i++)
        cout << "NT"[a[ii[l]] < a[i]];
    cout << '\n';
}