Submission

Status:

[PPPPP][-SSSS]

Subtask/Task Score:

{50/50}{0/50}

Score: 50

User: mantaggez

Problemset: จุดแวะพัก

Language: cpp

Time: 0.007 second

Submitted On: 2026-03-20 23:15:00

#include <bits/stdc++.h>

using namespace std;
using pis = pair<int, string>;

const int nx = 1e3+5;

int n, k;
vector<pis> ans;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin >> n >> k;
    cin.ignore();

    for(int i=0;i<n;i++) {
        int val = 0, cnt = 0;
        string line, name = "", num = "";
        getline(cin, line);
        // cout << line << '\n';

        for(auto& c : line) {
            if('a' <= c && c <= 'z') name += c;
            if('0' <= c && c <= '9') num += c;
            if((c == ' ' || c == *line.rbegin()) && !num.empty()) {
                val = stoi(num);
                if(val == k) {
                    ans.push_back({cnt, name});
                }
                // cout << val << ' ';
                num = "";
                cnt++;
            }
        }
        // cout << name << '\n';
    }

    sort(ans.begin(), ans.end(), [&](pis& x, pis& y) {
        if(x.first == y.first) return x.second < y.second;
        return x.first < y.first;
    });

    if(ans.size() > 3) {
        for(int i=0;i<3;i++) {
            cout << ans[i].second << ' ';
        }
    }
    else if(ans.empty()) {
        cout << -1 << '\n';
    }
    else {
        for(auto& [c, name] : ans) cout << name << ' ';
    }

    return 0;
}