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>
using namespace std;
int wagi[500009];
int sorted_wagi[500009];

bool ifcanbeking(int val, int n) {
    bool waitsame = true;
    long long weight = 0 + val;
    for(int i = 0; i < n; i++) {
        if (waitsame && sorted_wagi[i] == val)
        {
            waitsame = false;
            continue;
        }
        if (sorted_wagi[i] < weight) {
            weight += sorted_wagi[i];
        } else {
            return false;
        }
    }
    return true;
}

int main() {
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        scanf("%d", &wagi[i]);
        sorted_wagi[i] = wagi[i];
    }
    sort(sorted_wagi, sorted_wagi+n);
    int minyes = sorted_wagi[n-1] + 1;
    int maxno = sorted_wagi[0] - 1;
    for(int i = 0; i < n; i++) {
        if (wagi[i] >= minyes)
            printf("T");
        else if (wagi[i] <= maxno)
            printf("N");
        else {
            if(ifcanbeking(wagi[i], n)) {
                printf("T");
                minyes = wagi[i];
            } else {
                printf("N");
                maxno = wagi[i];
            }
        }
    }
}