Submission
Status:
[PPPPP][PPPPP]
Subtask/Task Score:
{50/50}{50/50}
Score: 100
User: dddrrrr
Problemset: จุดแวะพัก
Language: cpp
Time: 0.008 second
Submitted On: 2026-03-11 11:54:01
#include <bits/stdc++.h>
#define int long long
using namespace std;
struct P{
string name;
int rest;
};
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n ,k;
cin >> n >> k;
vector <P> data(n);
for(int i=0 ;i<n ;i++)data[i].rest = INT_MAX;
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;
vector <int> tmp;
int num ;
while(ss >> num){
tmp.emplace_back(num);
}
sort(tmp.begin() ,tmp.end());
auto it = unique(tmp.begin() ,tmp.end());
tmp.erase(it ,tmp.end());
for(int j=0 ;j<tmp.size() ;j++){
if(k == tmp[j]){
data[i].rest = j;
}
}
//for(auto it : data[i].mp)cout << it.first << ' ' << it.second << "\n";
}
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;
});
bool chk = false;
for(int i=0 ;i<3 ;i++){
if(data[i].rest == INT_MAX)break;
cout << data[i].name << ' ';
chk = true;
}
if(!chk)cout << -1;
return 0;
}