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
73
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

bool compareSums(const pair<int, unsigned long long>& a, const pair<int, unsigned long long>& b)
{
    return a.second < b.second;
}

int main() {
    std::ios::sync_with_stdio(false);

    int numberOfCatfishes;
    cin >> numberOfCatfishes;

    vector<pair<int, unsigned long long>> catfish(numberOfCatfishes);
    unsigned long long weight;

    for (int i = 0; i < numberOfCatfishes; i++) {
        cin >> weight;
        catfish[i] = make_pair(i, weight);
    }

    sort(catfish.begin(), catfish.end(), compareSums);

    vector<unsigned long long> catfishWeightSum(numberOfCatfishes);
    unsigned long long currentSum = 0;

    for (int i = 0; i < numberOfCatfishes; i++) {
        currentSum += catfish[i].second;
        catfishWeightSum[i] = currentSum;
    }

    unsigned long long currentSumToSet = catfishWeightSum[numberOfCatfishes - 1];

    for (int i = numberOfCatfishes - 2; i >= 0; i--) {
        if (catfish[i].second == catfish[i + 1].second) {
            catfishWeightSum[i] = catfishWeightSum[i + 1];
        }
        if (catfish[i].second == catfish[0].second) {
            catfishWeightSum[i] = catfishWeightSum[0];
        }
    }

    vector<bool> canBecomeCatfishKing(numberOfCatfishes, false);
    canBecomeCatfishKing[catfish[numberOfCatfishes - 1].first] = true;

    if (catfish[0].second == catfish[numberOfCatfishes - 1].second) {
        for (int i = 0; i < numberOfCatfishes; i++) {
            cout << "N";
        }
        return 0;
    }

    for (int i = numberOfCatfishes - 2; i >= 0; i--) {
        if (catfishWeightSum[i] > catfish[i + 1].second) {
            canBecomeCatfishKing[catfish[i].first] = true;
        }
        else {
            break;
        }
    }

    for (int i = 0; i < numberOfCatfishes; i++) {
        if (canBecomeCatfishKing[i]) {
            cout << "T";
        }
        else {
            cout << "N";
        }
    }
}