Submission

Status:

[PP-SS][PPPPP]

Subtask/Task Score:

{0/50}{50/50}

Score: 50

User: erng

Problemset: จุดแวะพัก

Language: cpp

Time: 0.008 second

Submitted On: 2026-03-05 18:53:59

#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++;
        }
    }
    if  (v.empty())
    {
        cout<<-1;
        return 0;
    }
    sort(v.begin(), v.end());
    
        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<<" ";
            }
        }
    
    
}