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
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
using namespace std;

using ll = long long;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);


    vector<pair<int, int>> fish{};
    int n{};
    cin >> n;
    int a{};
    int mi = 1e9+2;
    for (int i = 0; i < n; i++) {
        cin >> a;
        fish.push_back({a, i});
        mi = min(mi, a);
    }

    sort(fish.begin(), fish.end());
    vector<ll> prefs{};
    ll s{};
    for (auto f : fish) {
        s += f.first;
        prefs.push_back(s);
    }
    vector<char> ans(n, 'N');
    if (fish.back().first > mi) ans[fish.back().second] = 'T';
    for (int i = n-2; i >= 0; i--) {
        ll add = prefs[i];
        if (fish[i].first == mi) add = 0;
        if (add <= fish[i+1].first) break;
        ans[fish[i].second] = 'T';
    }
    for (auto el : ans) cout << el;
    cout << "\n";
}