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
55
56
57
58
59
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <tuple>
#include <random>
#include <cstdlib>
#include <time.h>
#include <limits>
#include <set>
#include <map>

#define INF 1000000000000000000

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(0);
    int n;
    std::cin >> n;
    std::vector<std::pair<int, int>> vec(n);
    for (int i = 0; i < n; i++)
    {
        std::cin >> vec[i].first;
        vec[i].second = i;
    }
    std::sort(vec.begin(), vec.end());
    long long sum = 0;
    std::vector<bool> feasible(n, true);
    int lastBlock = 0;
    int temp = 0;
    bool wasDiff = false;
    for (int i = 0; i < n; i++)
    {   
        if (i > 0 && vec[i].first != vec[i - 1].first)
            wasDiff = true;
        if (sum < vec[i].first) {
            lastBlock = i;
        }
        if (!wasDiff && (i < n - 1 && vec[i].first == vec[i + 1].first || (i > 0 && vec[i].first == vec[i - 1].first))) {
            temp += vec[i].first;
        }
        else {
            sum += vec[i].first;
            sum += temp;
            temp = 0;
        }
    }
    for (int i = 0; i < n; i++)
    {
        if (i < lastBlock)
            feasible[vec[i].second] = false;
    }
    for (int i = 0; i < n; i++)
    {
        std::cout << (feasible[i] ? "T" : "N");
    }
}