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

bool fishes[501000];

int main()
{
    long long n;
    vector<pair<long long,int>>sumy;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        sumy.push_back(make_pair(x,i));
    }
    sort(sumy.begin(),sumy.end());
    long long pocz=0,kon=n-1,mid;
    while(pocz<=kon)
    {
        mid=(pocz+kon)/2;
        bool complete=1;
        long long sum=sumy[mid].first;
        for(int i=0;i<n;i++)
        {
            if(sum>sumy[i].first && i!=mid)   sum+=sumy[i].first;
            else if(i==mid)                   continue;
            else
            {
                complete=0;
                break;
            }
        }
        if(complete==1) kon=mid-1;
        else            pocz=mid+1;
    }
    for(int i=0;i<n;i++)
    {
        fishes[i]=false;
    }
    for(int i=0;i<=kon;i++)
    {
        fishes[sumy[i].second]=true;
    }
    for(int i=0;i<n;i++)
    {
        if(fishes[i]==true) cout<<"N";
        else                cout<<"T";
    }
}