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
52
53
54
55
56
57
58
59
60
61
62
63
//runda 3C
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);

  long n, a, nsort, wiekszerowne;
  long long suma;
  vector<long> wejscie;
  vector<long> we_sort;
  vector<long long> poj_wart;
  vector<long long> poj_mno;
  vector<long long> sum_do;

  cin >> n;
  for(long iN = 0; iN < n; ++iN) {
	  cin >> a;
	  wejscie.push_back(a);
	  we_sort.push_back(a);
  }
  sort(we_sort.begin(), we_sort.end());

  a = 0;
  nsort = 0;
  for(long iN = 0; iN < n; ++iN)
	  if(we_sort[iN] != a) {
		  poj_wart.push_back(we_sort[iN]);
		  poj_mno.push_back(1);
		  ++nsort;
		  a = we_sort[iN];
	  } else
		  ++poj_mno[nsort - 1];

  suma = 0LL;

  for(long iN = 0; iN < nsort; ++iN) {
	  suma += ((long long)poj_wart[iN] * poj_mno[iN]);
	  sum_do.push_back(suma);
  }

  if(poj_wart.size() > 1)
	  wiekszerowne = poj_wart[nsort - 1];
  else
	  wiekszerowne = 2000000000;

  for(long iN = nsort - 2; iN > 0; --iN)
	  if(sum_do[iN] > poj_wart[iN + 1])
		  wiekszerowne = poj_wart[iN];
	  else
		  break;

  for(long iN = 0; iN < n; ++iN)
	  if(wejscie[iN] >= wiekszerowne)
		  cout << 'T';
	  else
		  cout << 'N';

  return 0;
}