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

int main() {
    int n, x, res = 0;
    long long sum = 0;
    std::vector<int> data;
    std::map<int, int> dict;
    std::cin >> n;
    while(n--) {
        std::cin >> x;
        data.push_back(x);
        auto found = dict.find(x);
        if(found == dict.end()) {
            dict[x] = 0;
        }
        dict[x]++;
    }
    for(auto const& el : dict) {
        // std::cout << el.first << " " << el.second << ": " << res << " " << sum << std::endl;
        if(!res || sum <= el.first) {
            res = el.first;
        }
        if(sum == 0 && el.second > 1) {
            res = 0;
        }
        sum += el.first * el.second;
    }
    for(auto const& el : data) {
        std::cout << (res && el>=res ? 'T' : 'N');
    }
    std::cout << std::endl;
    return 0;
}