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

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

    int n;
    std::cin >> n;

    std::vector<long long> v(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> v[i];
    }

    std::vector<long long> s = v;
    std::sort(s.begin(), s.end());

    std::vector<long long> p = s;
    for (int i = 1; i < n; ++i) {
        p[i] += p[i - 1];
    }

    for (int i = 0; i < n; ++i) {
        if (v[i] == s[0]) {
            std::cout << 'N';
            continue;
        }
        long long m = v[i];
        int last_lb = -1;
        while (1) {
            int lb = std::lower_bound(s.begin(), s.end(), m) - s.begin();
            if (last_lb == lb) {
                std::cout << 'N';
                break;
            }
            if (lb >= n) {
                std::cout << 'T';
                break;
            }
            m = p[lb - 1];
            if (s[lb - 1] < v[i]) m += v[i];
            last_lb = lb;
        }
    }

    return 0;
}