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

using namespace std;

struct sum {
    int weight;
    int number;
} wagi[500001];

long long psum[500001];
char answ[500001];

bool compsum (sum s1,sum s2) {
    return s1.weight < s2.weight;
}

int main() {
    int n; char c;
    scanf("%d",&n);

    int wei;
    for(int i=0; i < n; ++i) {
        scanf("%d",&wei);
        wagi[i].weight=wei;
        wagi[i].number=i;
    }

    sort(wagi,wagi+n,compsum);

    psum[0]=wagi[0].weight;
    for(int j=1; j<n; ++j) psum[j]=psum[j-1]+wagi[j].weight;

    int i=1;
    while(i<n && wagi[i].weight==wagi[0].weight) ++i;

    int cut=i;
    while(i<n) {
        int j=i+1;
        while(j<n && wagi[j].weight==wagi[i].weight) ++j;
        if(j<n && psum[j-1] <= wagi[j].weight) cut=j;
        i=j;
    }

    for(int j=0; j<cut; ++j) answ[wagi[j].number]='N';
    for(int j=cut; j<n; ++j) answ[wagi[j].number]='T';
    for(int j=0; j<n; ++j) printf("%c",answ[j]);
    printf("\n");
    return 0;
}