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
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include<algorithm>
using namespace std;



int main()
{

    std::ios_base::sync_with_stdio(false);
    long long int i, n, k, a;
    pair<int, int> tab[500100] = { {0,0} };
    bool ans[500100] = { false };
    long long int presum[500100];

    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> a;
        pair<int, int> p = { a,i };
        tab[i] = p;
    }

    sort(tab + 1, tab + n + 1);

    presum[0] = 0;
    i = 1;
    tab[n + 1] = tab[1];

    while (tab[i].first == tab[i + 1].first) {
        //cout << "i=" << i << '\n';
        presum[i] = presum[i - 1] + tab[i].first;
        i++;
        
    } 

    //printf("%d != %d\n", tab[i].first, tab[i + 1].first);
    int smallest = i;
   // cout << "smallest established " << smallest<<'\n';
    //we're on the last smallest fish

    while (i <= n) {
        presum[i] = presum[i - 1] + tab[i].first;
        i++;
    }


    for (i = n; i > smallest; i--) {
        if (presum[i] > tab[i + 1].first) {
            ans[tab[i].second] = true;
        }
        else
        {
            break;
        }
    }
    /*
    for (i = 1; i <= n; i++) {
        printf("%d ", tab[i].first);
    }
    cout << '\n' << '\n';
    for (i = 1; i <= n; i++) {
        printf("%d ", presum[i]);
    }
    cout << '\n' << '\n';*/
    for (i = 1; i <= n; i++) {
        if (ans[i] == true) {
            cout << "T";
        }
        else
        {
            cout << "N";
        }
    }
    cout << '\n';
    return 0;
}