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;
typedef long long ll;
#if DEBUG
#define LOG(...) printf(__VA_ARGS__)
#else
#define LOG(...)
#endif

int n;
vector<ll> v;
vector<ll> sor;

ll can_weight(ll w, int skip) // I bet it can be faster
{
    int i = 0;
    while (sor[i] < w && i < n)
    {
        if (i != skip)
            w += sor[i];
        i++;
    }
    return w;
}

int main()
{
    scanf("%d", &n);
    v.resize(n);
    for (int i = 0; i < n; ++i)
        scanf("%lld", &v[i]);

    sor = v;
    sort(sor.begin(), sor.end());

    ll biggest = sor[n - 1];

    int a = 0, b = n - 1;
    ll thres = LLONG_MAX;
    while (a <= b)
    {
        LOG("%d %d\n", a, b);
        int mid = (a + b) / 2;
        ll val = can_weight(sor[mid], mid);
        if (val > biggest && can_weight(sor[mid - 1], mid - 1) <= biggest)
        {
            thres = sor[mid];
            LOG("break at: %d\n", mid);
            break;
        }
        else if (val <= biggest)
            a = mid + 1;
        else
            b = mid;
    }
    LOG("threshold: %lld\n", thres);

    for (int i = 0; i < n; ++i)
    {
        if (v[i] >= thres)
            printf("T");
        else
            printf("N");
    }
    printf("\n");
}