Submission
Status:
[PPPPP][PPPPP]
Subtask/Task Score:
{50/50}{50/50}
Score: 100
User: Brabra475
Problemset: จุดแวะพัก
Language: cpp
Time: 0.008 second
Submitted On: 2026-03-10 21:43:12
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,k;
cin>>n>>k;
cin.ignore();
vector<pair<int,string>> dat;
bool found=false;
for(int i =0;i<n;i++){
string line;
getline(cin, line);
istringstream ss(line);
found=false;
string m;
ss>>m;
int x;
int cnt=0;
int found_where;
while(ss>>x){
if(x==k){
found_where=cnt;
found=true;
break;
}
cnt++;
}
if(found==true){
dat.push_back({found_where,m});
}
}
if(dat.empty()){ cout << -1; return 0; }
sort(dat.begin(), dat.end(), [](auto& a, auto& b){
if(a.first != b.first) return a.first < b.first;
return a.second < b.second;
});
for(int i = 0; i < min((int)dat.size(), 3); i++){
if(i > 0) cout << " ";
cout << dat[i].second;
}
}