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 <string>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;

struct sum {
	int index;
	int mass;
	long long mass_sum;
};

bool compareSums(sum a, sum b){
	return a.mass < b.mass;
}

int main(){
	int n, mass, min_mass;
	cin >> n;
	vector<sum> sums(n);
	for(int i = 0; i < n; i++){
		cin >> mass;
		sums[i] = {i, mass, 0} ;
	}
	sort(sums.begin(), sums.end(), compareSums);
	long long total_mass = 0;
	min_mass = sums[0].mass;
	for(int i = 0; i < n; i++){
		total_mass += sums[i].mass;
		if(sums[i].mass > min_mass){
			sums[i].mass_sum = total_mass;
		}
		else {
			sums[i].mass_sum = sums[i].mass;
		}
	}
	int next_biggest_fish = min_mass;
	string s(n, 'N');
	for(int i = n-1; i >= 0; i--){
		if(sums[i].mass_sum > next_biggest_fish){
			s[sums[i].index] = 'T';
			next_biggest_fish = sums[i].mass;
		}
	}
	cout << s;
	return 0;
}