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
// Autor: Mikołaj Janusz
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    vector<ll> weights(n), start_weights(n);
    ll current_sum = 0, minimal_weight = -1;
    string result = "";
    
    for (int i = 0; i < n; i++) {
        cin >> weights[i];
        current_sum += weights[i];
    }

    start_weights = weights;
    sort(weights.begin(), weights.end(), greater<ll>());
    minimal_weight = weights[0] + 1;

    for (int i = 0; i < n; i++) {
        if (weights[i] != weights[n-1] && (current_sum > weights[0] || current_sum > weights[i-1])) {
            minimal_weight = weights[i];
            current_sum -= weights[i];
        } else {
            break;
        }
    }

    for (int i = 0; i < n; i++)
        start_weights[i] >= minimal_weight ? result += "T" : result += "N";

    cout << result;
    return 0;
}