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
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, 
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool cmp(pair<long long, int> a, pair<long long, int> b){
    return (a.second < b.second);
}

int main(){
    int n;
    cin >> n;
    
    vector<pair<long long, int> > fish;
    
    long long big = 0;
    
    for(int i=0; i<n; i++){
        long long f;
        cin >> f;
        big = max(big, f);
        fish.push_back(make_pair(f, i));
    }
    
    sort(fish.begin(), fish.end());
    
    long long small = fish[0].first+1; 
    long long cur_w = 0;
    long long pos_w = fish[0].first;
    bool eaten = false;
    
    for(int i=1; i<n; i++){
        
        if(eaten == false){
            if(fish[i].first < small){
                pos_w += fish[i].first;
            }else{
                eaten = true;
                cur_w = pos_w;
                pos_w = 0;
                small = fish[i].first;
                cur_w += fish[i]. first;
            }
        }else{
            if(fish[i].first < cur_w){
                cur_w += fish[i].first;
            }else if(fish[i].first >= cur_w){
                small = fish[i].first;
                cur_w += fish[i].first;
            }
        }
        
        if(cur_w>big){
            break;
        }
        
        //cout << small << " " << cur_w << " " << pos_w << endl;
    }
    
    sort(fish.begin(), fish.end(), cmp);
    
    for(int i=0; i<n; i++){
        if(fish[i].first >= small){
            cout << "T";
        }else{
            cout << "N";
        }
    }
    
    cout << "\n";
}