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
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long int lli;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    lli n;
    cin >> n;
    vector<int> orig(n);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        orig[i] = a;
    }
    vector<int> fish(orig);
    sort(fish.begin(), fish.end());
    lli maxVal = fish[fish.size()-1];
    lli minWeight = INT32_MAX;
    lli start = 0;
    lli sum = fish[0];
    while (start < n-1 && fish[start] == fish[start+1]) {
        sum += fish[start+1];
        start++;
    }
    lli left = start + 1, right = left + 1;
    sum += fish[left];
    while (right < n) {
        if (sum > fish[right]) {
            sum += fish[right];
            right++;
        } else {
            sum += fish[right];
            left = right;
            right = left + 1;            
        }
    }
    if (left < n) {
        minWeight = fish[left];
    }
    string res;
    for (int i = 0; i < n; i++) {
        if (orig[i] >= minWeight) {
            res += 'T';
        } else {
            res += 'N';
        }
    }
    cout << res << '\n';
    return 0;
}