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
64
65
66
67
68
#include <bits/stdc++.h>
using namespace std;
vector <pair <long,long> > sumy;
bool moze2[500007];
long long n;
long long  funkcja (int indeks){
    long long wartosc = sumy[indeks].first;
    for (int i = 0; i < indeks; ++i){
        if (sumy[i].first >= wartosc){
            break;
        }
        wartosc += sumy[i].first;
    }
    for (int i = indeks+1; i < n; ++i){
        if (sumy[i].first >= wartosc){
            break;
        }
        wartosc += sumy[i].first;
    }
    return wartosc;
}
int binsearch(int p, int k, long long w){
    while(p != k){
        long long sr = (p+k+1)/2;
        if (funkcja(sr) <= w){
            p = sr;
        }
        else{
            k = sr-1;
        }
    }
    if (funkcja(k) <= w){
        k++;
    }
    return k;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cin >> n;
if (n == 1){
    cout << "T";
    return 0;
}
long long a;
for (int i = 0; i < n; ++i){
    cin >> a;
    sumy.push_back(make_pair(a,i));
}
sort (sumy.begin(), sumy.end());
int gdzie = binsearch(0, n-1, sumy[n-1].first);
if (funkcja(gdzie) > sumy[n-1].first){
for (int i = 0; i < gdzie; ++i){
    moze2[sumy[i].second] = false;
}
for (int i = gdzie; i < n; ++i){
    moze2[sumy[i].second] = true;
}
}
for (int i = 0; i < n; ++i){
    if (moze2[i] == true){
        cout << "T";
    }
    else{
        cout << "N";
    }
}
}