Submission
Status:
[PP-SS][PPPPP]
Subtask/Task Score:
{0/50}{50/50}
Score: 50
User: erng
Problemset: จุดแวะพัก
Language: cpp
Time: 0.007 second
Submitted On: 2026-03-05 18:46:42
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll nx=1005;
ll n, c, q, cnt;
string name, a, s;
vector<pair<ll,string>> v;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>q;
for (int i=1; i<=n; i++)
{
getline(cin, s);
stringstream ss(s);
ss >> name;
cnt=0;
while (ss >> c)
{
if (c==q) v.push_back({cnt, name});
cnt++;
}
}
sort(v.begin(), v.end());
if (v.empty()) cout<<-1;
else
{
if (v.size()<=3)
{
for (int i=0; i<v.size(); i++)
{
cout<<v[i].second<<" ";
}
}
else
{
for (int i=0; i<3; i++)
{
cout<<v[i].second<<" ";
}
}
}
}