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
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#define MAX 1000009


int result[MAX];
int main()
{
    int n;
    std::vector<std::pair<long long, int>> fish;
    
    std::cin >> n;
    
    for (int i=0; i<n; i++) {
        int v;
        std::cin >> v;
        fish.push_back(std::make_pair(v, i));
    }
    
    std::sort(fish.begin(), fish.end());
        
    long long sum = 0, li = 1;
    for (int i=0; i<n; i++) {
        if (fish[i].first == fish[0].first) {
            sum += fish[i].first;
            li = i + 1;
            continue;
        }
        
        while (li < n && (li <= i || fish[li].first < sum)) {
            sum += fish[li++].first;
        }
        
        if (li == n) {
            result[fish[i].second] = true;
        }
    }
    
    for (int i=0; i<n; i++) if (result[i]) std::cout << "T"; else std::cout << "N";
}