Submission

Status:

[P-SSS][PPP-S]

Subtask/Task Score:

{0/50}{0/50}

Score: 0

User: dddrrrr

Problemset: จุดแวะพัก

Language: cpp

Time: 0.019 second

Submitted On: 2026-03-11 11:22:58

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

struct P{
	string name;
	map <int ,int> mp;
	int rest;
};

int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n ,k;
	cin >> n >> k;
	vector <P> data(n);
	
	cin.ignore();
	
	for(int i=0 ;i<n ;i++){
		string str;
		getline(cin ,str);
		
		stringstream ss(str);
		string word;
		
		ss >> word;
		data[i].name = word;
		//cout << data[i].name;
		
		int num ,j=1;
		while(ss >> num){
			data[i].mp[num] = j;
			j++;
		}
		
		//for(auto it : data[i].mp)cout << it.first << ' ' << it.second << "\n";	
	}
	
	for(int i=0 ;i<n ;i++){
		if(data[i].mp.count(k))data[i].rest = data[i].mp[k];
		else data[i].rest = INT_MAX;
	}
	//cout << data[0].rest;
	

	sort(data.begin() ,data.end() ,[](struct P &a ,struct P &b){
		if(a.rest != b.rest)return a.rest < b.rest;
		return a.name < b.name;
	});
	
	for(int i=0 ;i<3 ;i++){
		if(data[i].rest == INT_MAX)break;
		cout << data[i].name << ' ';
	}
	
	
	
	return 0;
}