Submission

Status:
[PPPPP][PPPPP]

Score: 100

User: dwad2

Problemset: จุดแวะพัก

Language: cpp

Time: 0.023 second

Submitted On: 2025-03-21 21:14:55

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    cin.ignore();

    vector<string> name(n);
    vector<int> count(n, 0);
    vector<bool> check(n, false);

    for (int i = 0; i < n; i++) {
        string line;
        getline(cin, line);

        stringstream ss(line);
        ss >> name[i];

        int temp;
        while (ss >> temp) {
            if (temp < k) {
                count[i]++;
            }
            if (temp == k) {
                check[i] = true;
            }
        }
    }

    priority_queue<pair<int, string>, vector<pair<int, string>>, greater<pair<int, string>>> pq;

    for (int i = 0; i < n; i++) {
        if (check[i]) {
            pq.push({count[i], name[i]});
        }
    }

    if(pq.empty()) {
        cout << -1;
    }
    else {
        int ncount = 0;
        while (!pq.empty()) {
            cout << pq.top().second << " ";
            ncount++;
            pq.pop();
            if(ncount == 3) {
                return 0;
            }
        }
    }

    return 0;
}