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

map<long long, long long> howManyWithGivenMass;
map<long long, bool> canBeKingOfSea;
vector<long long> sums;

int main()
{
    int n;
    long long a;
    cin>>n;
    long long maxSum=0;
    long long wholeSum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        howManyWithGivenMass[a]++;
        maxSum=max(maxSum,a);
        wholeSum+=a;
        sums.push_back(a);
    }
    long long actualSum=0;
    long long previousSum = maxSum;
    for(auto kv = howManyWithGivenMass.rbegin(); kv!=howManyWithGivenMass.rend();kv++)
    {
        //cerr<<"Checking "<<(*kv).first<<" "<<(*kv).second<<endl;;
        if(true
            and (((*kv).second>1 and wholeSum-(*kv).first*(*kv).second-actualSum>0) or (*kv).second==1)
            and ((wholeSum-actualSum>previousSum)or((*kv).first==maxSum and (*kv).second)==1)
            )
            canBeKingOfSea[(*kv).first]=true;
        else
            break;
        actualSum+=(*kv).first*(*kv).second;
        previousSum=(*kv).first;
    }
    for(auto a: sums)
        switch (canBeKingOfSea[a])
        {
        case true: cout<<"T";
            break;
        case false: cout<<"N";
        }
    cout<<endl;
    return 0;
}