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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr int MAX = 5e5 + 1234;

ll sorted[MAX];
ll ryby[MAX];
int N;

bool check(ll ryba)
{
    bool skipped = false;
    ll suma = ryba;
    int i = 0;

    // cout << "ryba= " << ryba << "\n";
    for (; i < N; ++i)
    {
        if (sorted[i] == ryba && !skipped)
        {
            skipped = true;
            continue;
        }

        // cout << "Suma= " << suma << " sorted[i]= " << sorted[i] << "\n";

        if (suma > sorted[i])
        {
            suma += sorted[i];
        }
        else
            break;
    }

    // cout << "ZWRACAM: " << (i == N) << " dla ryby= " << ryba << "\n"; 

    if (i == N)
        return true;
    else
        return false;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> N;

    for (int i = 0; i < N; ++i)
    {
        cin >> ryby[i];
        sorted[i] = ryby[i];
    }

    sort(sorted, sorted + N);

    int pocz = 0, kon = N - 1, ost = -1;

    while (kon - pocz >= 0)
    {
        int mid = (pocz + kon) / 2;
        bool res = check(sorted[mid]);

        if (res)
        {
            ost = sorted[mid];
            kon = mid - 1;
        }
        else
        {
            pocz = mid + 1;
        }
    }

    if (ost == -1)
        ost = sorted[N - 1] + 213;

    // cout << "DZIALA DLA RYBY CO NAJMNIEJ= " << ost << "\n";

    for (int i = 0; i < N; ++i)
    {
        if (ryby[i] >= ost)
            cout << "T";
        else 
            cout << "N";
    }

    cout << endl;
    

    return 0;
}