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
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;


int main(){
    int n;
    cin >> n;
    vector<pair<int, int>> sumy;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        sumy.push_back(make_pair(x, i));
    }
    sort(sumy.begin(), sumy.end(), [](pair<int, int> p1, pair<int, int> p2){
        return p1.first < p2.first;
    });
    int index = 0;
    long long sum = 0;
    long long tempSum = 0;
    for(int i=0;i<n;i++){
        if(sum<=sumy[i].first){
            index = i;
        }
        sum += tempSum;
        tempSum = 0;
        while(i+1<n&&sumy[i].first==sumy[i+1].first){
            tempSum += sumy[i].first;
            i++;
        }
        if(sum!=0){
            sum+=tempSum;
            tempSum = 0;
        }
        sum += sumy[i].first;
        
    }
    vector<bool> ans(n);
    for(int i=0;i<n;i++){
        if(i<index || sumy[0].first == sumy[n-1].first){
            ans[sumy[i].second]=false;
        }else {
            ans[sumy[i].second]=true;
        }
    }
    for(int i=0;i<n;i++){
        cout << (ans[i] ? "T" : "N");
    }
    cout << endl;
}