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
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
int n, res;
vector<int> sumy, posortowane;
unordered_set<int> masy;
bool solve(int a, int pos)
{
    ll x = a;
    for (int i = 0; i < n; ++i)
    {
        if (pos == i)
            continue;
        if (x > posortowane[i])
            x += posortowane[i];
        else
            return false;
    }
    return true;
}
int binarySearch()
{
    int mid, l = 0, r = n - 1;
    while (l <= r)
    {
        mid = (l + r) / 2;
        if (solve(posortowane[mid], mid))
            r = mid;
        else
            l = mid + 1;
        if (l == r)
            break;
    }
    return posortowane[l];
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    sumy.resize(n);
    for (auto &i : sumy)
    {
        cin >> i;
        masy.insert(i);
    }
    if (masy.size() > 1)
    {
        posortowane = sumy;
        sort(posortowane.begin(), posortowane.end());
        int prog = binarySearch();
        for (auto &i : sumy)
            if (i >= prog)
                cout << 'T';
            else
                cout << 'N';
        cout << '\n';
        return 0;
    }
    else
        for (int i = 0; i < n; ++i)
            cout << 'N';
    cout << '\n';
}