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

using namespace std;

struct Participant {
    int id;
    bool willing;
    int previousFinals;
};

int main() {
    int n;
    cin >> n;
    
    vector<Participant> participants;
    
    // Wczytanie danych
    for (int i = 1; i <= n; i++) {
        string s;
        int x;
        cin >> s >> x;
        
        bool willing = (s == "TAK");
        participants.push_back({i, willing, x});
    }
    
    // Filtracja zawodników, którzy chcą i mogą uczestniczyć
    vector<Participant> eligible;
    for (const auto& p : participants) {
        if (p.willing) {
            eligible.push_back(p);
        }
    }
    
    // Wybór 20 finalistów
    vector<int> finalists;
    
    // Pierwsza dziesiątka - top 10 z listy
    for (int i = 0; i < 10 && i < eligible.size(); i++) {
        finalists.push_back(eligible[i].id);
    }
    
    // Druga dziesiątka - kolejni najlepsi bez tych z ≥2 startami
    int count = 0;
    for (int i = 10; i < eligible.size() && count < 10; i++) {
        if (eligible[i].previousFinals < 2) {
            finalists.push_back(eligible[i].id);
            count++;
        }
    }
    
    // Sortowanie ID finalistów
    sort(finalists.begin(), finalists.end());
    
    // Wypisanie wyników
    for (int i = 0; i < finalists.size(); i++) {
        cout << finalists[i];
        if (i < finalists.size() - 1) {
            cout << " ";
        }
    }
    cout << endl;
    
    return 0;
}