Submission

Status:
[PPPPP][PPPPP]

Score: 100

User: osensunny

Problemset: จุดแวะพัก

Language: cpp

Time: 0.009 second

Submitted On: 2025-03-22 22:24:29

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

#define si pair<int, string>

vector<si> info;
string str;
int N, K;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	
	cin >> N >> K;
	for(int i=0; i<=N; i++){
		getline(cin, str);
		int cnt=0;
		string name, num;
		for(auto c: str){
			if(c >= 'a' && c <= 'z') name.push_back(c);
			else if(c == ' ') num.clear();
			else{
				num.push_back(c);
				if(stoi(num) == K){
					info.push_back({cnt, name});
					break;
				}
				cnt++;
			}
		}
	}
	
	if(info.empty()){
		cout << -1;
		return 0;
	}
	sort(info.begin(), info.end());

	int cnt=0;
	for(auto tmp: info){
		cout << tmp.second << ' ';
		cnt++;
		if(cnt == 3) return 0;
	}
	
	return 0;
}