Submission

Status:

[PPPPP][PPPPP]

Subtask/Task Score:

{50/50}{50/50}

Score: 100

User: House123

Problemset: จุดแวะพัก

Language: cpp

Time: 0.013 second

Submitted On: 2026-03-10 20:40:11

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


//create my own pair and it's sorting functoim
struct visitor {
    string name;
    int foundK_index;

    bool operator<(const visitor& other) const {
        //my logic here
        if(foundK_index != other.foundK_index){
            //sort ascending
            return foundK_index < other.foundK_index;
        }

        //sort alphabetically ascendding
        return name < other.name;


    }
};

int main(){
    vector<visitor> people;
    int n,k;
    cin >> n >> k;
    //read data
    for(int i = 0; i < n; i ++ ){
        string name;
        cin >> name;
        string line;
        getline(cin,line);
        stringstream ss(line);
        //loop until NULL
        int cnt = 0;
        bool foundK = false;
        int numK_index = -1;
        int stop;
        while(ss >> stop){

            if(stop == k){
                foundK = true;
                numK_index = cnt;
                break;
            }
            cnt++;
        }


        if(foundK == true){
            people.push_back({name,numK_index});
        }

    }
    //if empty
    if(people.empty()){
        cout << -1;
        return 0;
    }
    //after getting every name we should sort it
    sort(people.begin(),people.end());
    //after sorting we will print the answer but first we should find the length
    int lengthy = min((int)people.size(),3);

    for(int i = 0; i < lengthy;i++){
        cout << people[i].name << " ";
    }

    return 0;

}