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

typedef long long ll;

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

    ll n;
    cin >> n;

    ll suma = 0, ma = 0, mi = pow(10,9);
    vector<ll> sums(n);
    map<ll, vector<ll>> position;
    for(ll i = 0; i < n; i++){
        cin >> sums[i];
        ma = max(sums[i], ma);
        mi = min(sums[i], mi);
        if(position.find(sums[i]) == position.end()){
            position[sums[i]] = {};
        }
        position[sums[i]].push_back(i);
    }

    /*
    unordered_set<int> s(sums.begin(), sums.end());
    sums.assign(s.begin(), s.end());
    n = sums.size();
    */

    sort(sums.begin(), sums.end());
    string result(n, 'T');

    ll j = 0;
    while(j < n){
        ll el = sums[j];
        suma += el;
        if(el == mi){
            for(ll i = 0; i < position[el].size(); i++){
                result[position[el][i]] = 'N';
            }
            j++;
        }
        else if(el == ma){
            break;
        }
        else{
            ll k = j+1, part_suma = 0;
            bool isBigger = false;
            while(suma + part_suma > sums[k] && k < n){
                part_suma += sums[k];
                if(suma + part_suma > ma){
                    isBigger = true;
                    break;
                }
                k++;
            }
            if(isBigger || k == n) break;
            else{
                for(ll i = j; i < k; i++){
                    for(int m = 0; m < position[sums[i]].size(); m++) result[position[sums[i]][m]] = 'N';
                }
            }
            j = k + 1;
            suma += part_suma;
        }
    }

    cout << result;

    return 0;
}