Submission

Status:

[PPPPP][PPPPP]

Subtask/Task Score:

{50/50}{50/50}

Score: 100

User: colo39

Problemset: จุดแวะพัก

Language: cpp

Time: 0.007 second

Submitted On: 2026-11-20 21:19:02

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


int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n,k;
    cin >> n >> k;
    int cur = 0;
    string name;
    vector<pair<string,int>> vec;
    int cnt = 0;
    string s;
    while (cin >> s) {
        
        if (!isdigit(s[0])) {
                cur++;
                name = s;
                cnt = 0;
                continue;
        }
        cnt++;
        if (stoi(s) == k) {
            vec.push_back({name,cnt});
        }

    }

    if (vec.size() == 0) {
        cout << -1;
    } else {
        sort(vec.begin(),vec.end(),[](const auto &a, const auto &b){
            if (a.second != b.second) return a.second < b.second;
            return a.first < b.first;
        });

        for (int i = 0;i < min(3,(int) vec.size());i++) {
            cout << vec[i].first << " ";
        }
    }
    return 0;
}