Submission

Status:
[PPP-S][-SSSS]

Score: 0

User: nongbilly

Problemset: จุดแวะพัก

Language: cpp

Time: 0.019 second

Submitted On: 2025-03-24 21:14:21

#include <bits/stdc++.h>
using namespace std;

// int priority(char str){
//     if(str == '1') return 1;
//     if(str == '2') return 2;
//     if(str == '3') return 3;
//     else return 0;
// }

// string infixTopostfix(string order){
//     int len = order.length();
//     stack<char> st;
//     string ans;

//     int i = 0;
//     while(i < len){
//         char x = order[i];

//         if(!isdigit(x) && x != '[' && x != ']') ans.push_back(x);

//         else if(isdigit(x)){
//             while(!st.empty() && priority(st.top()) >= priority(x)){
//                 ans.push_back(st.top());
//                 st.pop();
//             }
//             st.push(x);
//         }

//         else if(x == '[') st.push(x);

//         else if(x == ']'){
//             while(!st.empty() && st.top() != '['){
//                 ans.push_back(st.top());
//                 st.pop();
//             }
//             st.pop();
//         }

//         i++;
//     }

//     if(!st.empty()){
//         while(!st.empty()){
//             ans.push_back(st.top());
//             st.pop();
//         }
//     }

//     return ans;
// }

// int wrap(string order){
//     stack<int> price;

//     for(int i = 0; i < order.length(); i++){
//         char x = order[i];

//         if(!isdigit(x)) price.push(20);
//         else{
//             if(x == '3'){
//                 int a = price.top();
//                 price.pop();
//                 int b = price.top();
//                 price.pop();

//                 int c = (a + b) * 0.16 + a + b;
//                 price.push(c);
//             }

//             if(x == '2'){
//                 int a = price.top();
//                 price.pop();
//                 int b = price.top();
//                 price.pop();
                
//                 int c = (a + b) * 0.08 + a + b;
//                 price.push(c);
//             }

//             if(x == '1'){
//                 int a = price.top();
//                 price.pop();
//                 int b = price.top();
//                 price.pop();
                
//                 int c = (a + b) * 0.04 + a + b;
//                 price.push(c);
//             }
//         }
//     }

//     return price.top();
// }

// int main(){
//     string order;
//     cin >> order;

//     string neworder = infixTopostfix(order);
//     int cost = wrap(neworder);

//     cout << cost << endl;
// }

// int main(){
//     int n;
//     cin >> n;

//     vector<int> num(n);
//     for(int i = 0; i < n; i++){
//         cin >> num[i];
//     }

//     vector<int> result(n);
//     stack<int> st;

//     for(int i = 0; i < n; i++){
//         while (!st.empty() && num[st.top()] >= num[i]) {
//             st.pop();
//         }
        
//         result[i] = (st.empty() ? 0 : st.top() + 1);
//         st.push(i);
//     }

//     for(auto &r : result){
//         cout << r << " ";
//     }
// }

vector<int> rest(string r){
    vector<int> ans;
    for (char c : r) {
        if (isdigit(c)) ans.push_back(c - '0');
    }

    return ans;
}

int visit(vector<int> &r, int k){
    for (int i = 0; i < r.size(); i++) {
        if (r[i] == k) return i + 1;
    }
    return -1;
}

int main(){
    int n, k;
    cin >> n >> k;

    vector<pair<string, int>> tourist;

    for(int i = 0; i < n; i++){
        string name;
        cin >> name;
        cin.ignore();

        string r;
        getline(cin, r);
        vector<int> resting = rest(r);

        int v = visit(resting, k);

        if(v != -1) tourist.push_back({name, v});
    }

    sort(tourist.begin(), tourist.end(), [](auto &a, auto &b){
        if(a.second == b.second) return a.first < b.first;
        return a.second < b.second;
    });

    for (int i = 0; i < min(3, (int)tourist.size()); i++) {
        cout << tourist[i].first << " ";
    }

    if(tourist.empty()) cout << -1;

    return 0;

}