Submission
Status:
[PPPPP][PPPPP]
Subtask/Task Score:
{50/50}{50/50}
Score: 100
User: nemuchannnUwU
Problemset: จุดแวะพัก
Language: cpp
Time: 0.014 second
Submitted On: 2026-03-11 13:21:01
#include<bits/stdc++.h>
using namespace std;
static bool sss(pair<string,int> &a,pair<string,int> &b){
if (a.second==b.second) return a.first<b.first;
return a.second<b.second;
}
int main(){
cin.tie(nullptr)->sync_with_stdio();
vector<pair<string,int>> ans;
int n,k; cin >> n >> k;
cin.ignore();
while(n--){
string s;
getline(cin, s);
stringstream ss(s);
string name;
ss >> name;
string word;
int cnt = 0;
bool found = false;
while(ss >> word){
int point = stoi(word);
if (point == k) {
found = true;
break;
}
cnt++;
}
if (found)
ans.push_back({name,cnt});
}
if (ans.empty()){
cout << -1;
return 0;
}
sort(ans.begin(),ans.end(),sss);
int limit = min((int)ans.size(), 3);
for (int i = 0; i < limit; i++) {
cout << ans[i].first << " ";
}
}