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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>

using namespace std;

class Item {
public:
    int a;
    int index;

    Item(int aa, int ii) : a(aa), index(ii) {};
};

int lowest(const void *a, const void *b) {
    return ((*(Item **) a)->a - (*(Item **) b)->a);
}

void random_shuffle(const vector<Item, allocator<Item>>::iterator first,
                    const vector<Item, allocator<Item>>::iterator last) {
    int n = last - first;
    for (int i = 0; i < n; i++) {
        swap(first[i], first[rand() % n]);
    }
}

vector<Item*> v;

int main() {

    int n;
    cin >> n;
    char *output = new char[n];

    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        v.push_back(new Item(a, i));
    }

//    random_shuffle(v.begin(), v.end());
    qsort(&v[0], v.size(), sizeof(Item*), lowest);

    int first = v[0]->a;
    long long sum = first;
    int i;
    for(i = 1; i < n; i++) {
        sum += v[i]->a;
        if(v[i]->a > first) {
            break;
        }
    }
    int noIndex = i;

    for (++i;i < n; i++) {
        Item *item = v[i];

        if (item->a >= sum) {
            noIndex = i;
        }
        sum += item->a;
    }

    for(i = 0; i < noIndex; i++) {
        output[v[i]->index] = 'N';
    }
    for(i = noIndex; i < n; i++) {
        output[v[i]->index] = 'T';
    }

    cout << output << endl;
//    delete[] output;

    return 0;
}