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<bits/stdc++.h>
using namespace std;
using lld = long long;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	int n;
	cin >> n;

	vector<lld> t(n);
	for(lld& i : t)
		cin >> i;

	vector<lld> p = t;
	sort(p.begin(), p.end());
	vector<lld> pref = p;
	for(int i=1;i<n;i++)
		pref[i] += pref[i-1];

	string res(n,' ');
	for(int i=0;i<n;i++) {
		int idx = lower_bound(p.begin(), p.end(), t[i])-p.begin();
		while(idx < n-1) {
			lld weight = pref[idx];
			int n_idx = lower_bound(p.begin(), p.end(), weight)-p.begin()-1;
			if(n_idx <= idx)
				break;
			idx = n_idx;
		}

		res[i] = (idx == n-1 ? 'T' : 'N');
	}

	cout << res << "\n";

	return 0;
}