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
69
70
71
72
/*
 * sum.cpp
 *
 *  Created on: Dec 9, 2021
 *      Author: A.Mulawa
 */

#include <bits/stdc++.h>

using namespace std;

struct data_s{
    unsigned int v,p;
    char w;
};

static bool data_sorter_v(data_s a, data_s b)
{
   return a.v < b.v;
};

static bool data_sorter_p(data_s a, data_s b)
{
   return a.p < b.p;
};

int main(int argc, char **argv)
{
    data_s t[500000] = {};

    int n, d;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &d);
        t[i].p = i;
        t[i].v = d;
        t[i].w = 'T';
    }

    sort(t, t+n, &data_sorter_v);

    for (int i = 0; i < n; i++)
    {
        unsigned long long  s = t[i].v;
        int j;
        for (j = 0; j < n; j++)
        {
           if(i != j)
           {
               if (s > t[j].v)
               {
                   s += t[j].v;
               }
               else
               {
                   t[i].w = 'N';
                   break;
               }
           }
        }

    }

    sort(t, t+n, &data_sorter_p);
    for (int i = 0; i < n; i++)
    {
        printf("%c",t[i].w);
    }

    return 0;
};