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
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstdio>
using namespace std;
int n,l,r,s,y;
bool b[500005];
long long x,sum;
pair <long long,int> t[500005];
int main(){
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%lld",&t[i].first);
    sum+=t[i].first;
    t[i].second=i;
  }
  sort(t,t+n);
  l=0;
  r=n-1;
  y=n;
  while(r>=l){
    s=(r+l)/2;
    x=t[s].first;
    for(int i=0;i<n;i++){
      if(i==s) continue;
      if(t[i].first<x) x+=t[i].first; else break;
    }
    if(x==sum){
      y=s;
      r=s-1;
    }else{
      l=s+1;
    }
  }
  for(int i=y;i<n;i++)
    b[t[i].second]=1;
  for(int i=0;i<n;i++) if(b[i]) printf("T"); else printf("N");
  return 0;
}