Submission

Status:

[PP-SS][PPPPP]

Subtask/Task Score:

{0/50}{50/50}

Score: 50

User: Ryuthin94

Problemset: จุดแวะพัก

Language: cpp

Time: 0.008 second

Submitted On: 2026-03-06 11:04:02

#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k;
    cin >> n >> k;

    vector<pair<int, string>> v;
    for (int i = 0; i < n; i++)
    {
        string line;
        getline(cin, line);
        stringstream ss(line);

        string name;
        ss >> name;
        if (name.empty())
            continue;

        int temp;
        int x = 0;
        bool found = false;
        while (ss >> temp)
        {
            if (temp == k)
            {
                v.push_back({x, name});
                found = true;
                break;
            }
            x++;
        }
    }

    sort(v.begin(), v.end());
    if (v.empty())
    {
        cout << -1;
        return 0;
    }

    int lim = min(3, (int)v.size());
    for (int i = 0; i < lim; i++)
    {
        if (i)
            cout << ' ';
        cout << v[i].second;
    }

    return 0;
}