Submission
Status:
[PPPPP][PPPPP]
Subtask/Task Score:
{50/50}{50/50}
Score: 100
User: mightbeputter
Problemset: จุดแวะพัก
Language: cpp
Time: 0.003 second
Submitted On: 2026-03-27 21:07:54
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
struct hambunger{
int cnt;
string str;
bool operator<(const hambunger &o) const{
if(cnt != o.cnt) return cnt < o.cnt;
for(int i=0;true;i++){
if(str[i] != o.str[i]) return str[i] < o.str[i];
}
}
};
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
int n;
string k;
cin >> n >> k;
string temp;
getline(cin , temp);
vector<hambunger> ans;
for(int i=1;i<=n;i++){
string a, name;
getline(cin, a);
// cout << i << " " << a << "\n";
int cnt = -1, j=0;
for(auto& x : a){
if(x == ' '){
cnt++;
j=0;
continue;
}
if(cnt == -1){
name.push_back(x);
}else if(j != -1){
if(x == k[j]) j++;
else j = -1;
if(j == k.length()){
ans.push_back({cnt, name});
break;
}
}
}
}
sort(ans.begin(), ans.end());
int cnt = 0;
for(auto& x : ans) {
if(cnt == 3) break;
cout << x.str << " ", cnt++;
}
if(cnt == 0) cout << "-1";
return 0;
}