Submission

Status:

[PPPPP][PPPPP]

Subtask/Task Score:

{50/50}{50/50}

Score: 100

User: Few500

Problemset: จุดแวะพัก

Language: cpp

Time: 0.007 second

Submitted On: 2026-03-21 21:19:45

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, m;
    cin >> n >> m;
    cin.ignore();
    vector<pair<int, string>> ans;
    for (int i=0; i<n; i++)
    {
        string l, name;
        getline(cin, l);
        stringstream ss(l);
        ss >> name;

        int x = 0, time = 0;
        while (ss >> x)
        {
            if (x == m){
                ans.push_back({time, name});
                break;
            }
            time++;
        }
    }

    sort(ans.begin(), ans.end());

    if (ans.empty())
        cout << "-1";

    if (ans.size() >= 3)
        for (int i = 0; i < 3; i++)
            cout << ans[i].second << ' ';
    else
        for (int i = 0; i < ans.size(); i++)
            cout << ans[i].second << ' ';
    return 0;
}