Submission

Status:

[P-SSS][PPP-S]

Subtask/Task Score:

{0/50}{0/50}

Score: 0

User: kittipos

Problemset: จุดแวะพัก

Language: cpp

Time: 0.007 second

Submitted On: 2026-03-05 09:24:53

#include <algorithm>
#include <iostream>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;

struct Tourist {
  int stop_before_k;
  string name;
};

bool cmp(Tourist t1, Tourist t2) {
  return make_pair(t1.stop_before_k, t1.name) <
         make_pair(t2.stop_before_k, t2.name);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, k;
  cin >> n >> k;

  string line;
  getline(cin, line);
  vector<Tourist> tourists;
  for (int i = 0; i < n; i++) {
    getline(cin, line);
    stringstream ss(line);

    string name;
    ss >> name;

    int stop;
    int count = 0;
    bool found = false;
    while (ss >> stop) {
      if (stop == k) {
        found = true;
        break;
      }
      count ++;
    }
    if (found) {
      tourists.push_back({count, name});
    }
  }

  sort(tourists.begin(), tourists.end(), cmp);

  int count = 0;
  for (int i = 0; i < min(3, static_cast<int>(tourists.size())); i++) {
    cout << tourists[i].name << ' ';
  }

  return 0;
}