Submission
Status:
[PPPPP][PPPPP]
Subtask/Task Score:
{50/50}{50/50}
Score: 100
User: cyblox_boi
Problemset: จุดแวะพัก
Language: cpp
Time: 0.007 second
Submitted On: 2025-10-24 01:16:39
#include <algorithm>
#include <iostream>
#include <sstream>
using namespace std;
struct Visitor {
string name;
int visits;
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
cin.ignore();
vector<Visitor> visitors;
for (int i = 0; i < n; i++) {
string command;
getline(cin, command);
stringstream ss(command);
string name;
ss >> name;
int num;
int count = 0;
while (ss >> num) {
if (num == k) {
visitors.push_back({name, count});
break;
}
count++;
}
}
sort(visitors.begin(), visitors.end(), [](Visitor &a, Visitor &b) {
if (a.visits == b.visits) {
return a.name < b.name;
}
return a.visits < b.visits;
});
if (!visitors.empty()) {
for (int i = 0; i < (visitors.size() > 3 ? 3 : visitors.size()); i++) {
cout << visitors[i].name << ' ';
}
} else {
cout << -1;
}
cout << '\n';
return 0;
}