Submission
Status:
[PPPPP][PPPPP]
Score: 100
User: Cmoss9
Problemset: จุดแวะพัก
Language: cpp
Time: 0.003 second
Submitted On: 2025-03-23 14:38:43
#include <bits/stdc++.h>
using namespace std;
vector<pair<string,int>> v;
bool comp(const pair<string,int>& a, const pair<string,int>& b) {
if (a.second == b.second) return a.first < b.first;
return a.second < b.second;
}
int main () {
ios_base::sync_with_stdio(0);cin.tie(0);
int n,k;
cin >> n >> k;
for (int i = 0;i<n;i++) {
string name;
cin >> name;
string str;
int num = 0 ,foundat = INT_MAX;
getline(cin,str);
for (int j = 0;j<str.size();j++) {
if (str[j] != ' ') {
num = num*10 + (str[j] - '0');
//cout << num << " ";
} else {
num = 0;
}
if (num == k) {
foundat = j+1;
}
}
if (foundat != INT_MAX) {
v.emplace_back(name,foundat);
}
}
if (v.empty()) {
cout << "-1";
return 0;
}
sort(v.begin(),v.end(),comp);
for (int i = 0;i<3&&i<v.size();i++) {
cout << v[i].first << " ";
}
}