Submission

Status:

[PxSSS][-SSSS]

Subtask/Task Score:

{0/50}{0/50}

Score: 0

User: Few500

Problemset: จุดแวะพัก

Language: cpp

Time: 0.009 second

Submitted On: 2026-03-21 21:00:36

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

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

    struct Card{
        string name;
        vector<int> rested;
        int time = 2e9;
    };
    int n, m;
    cin >> n >> m;
    vector<Card> travellers(n);
    for(int i=0; i<n; i++){
        cin >> travellers[i].name;

        string l;
        getline(cin, l);
        stringstream ss(l);

        int x;
        while(ss >> x)
            travellers[i].rested.push_back(x);
    }

    for(int i=0; i<n; i++){
        for(int j=0; j<travellers[i].rested.size(); j++){
            if(travellers[i].rested[j] == m){
                travellers[i].time = j;
                break;
            }
        }
    }

    sort(travellers.begin(), travellers.end(), [](auto a, auto b){return a.name < b.name;});
    sort(travellers.begin(), travellers.end(), [](auto a, auto b){return a.time < b.time;});

    for(int i=0; i<3; i++){
        if(travellers[i].time != 2e9)
            cout << travellers[i].name << ' ';
    }
    return 0;
}