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

bool cannot[500010];

vector <pair <int, int> > v;

int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int x;
for (int i = 0; i < n; i++) {
    cin >> x;
    v.push_back({x, i});
}
sort(v.begin(), v.end());
int64_t sum = 0;
int lastset = -1;
int poz = 1;
cannot[v[0].second] = true;
sum += v[0].first;
while(poz < n && v[poz].first == v[poz-1].first) {
    cannot[v[poz].second] = true;
    sum += v[poz].first;
    poz++;
}
for (int i = poz; i < n; i++) {
    if (v[i].first >= sum) {
        for (int j = poz; j < i; j++) {
            cannot[v[j].second] = true;
        }
    }
    sum += v[i].first;
}
for (int i = 0; i < n; i++) {
    cout << (cannot[i] ? "N" : "T");
}
}