Submission

Status:

[PPPPP][PPPPP]

Subtask/Task Score:

{50/50}{50/50}

Score: 100

User: Pung

Problemset: จุดแวะพัก

Language: cpp

Time: 0.023 second

Submitted On: 2026-03-09 07:15:48

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

int main() 
{
    int n,k;
    cin >> n >> k;
    vector<pair<int,string>> v;
    
    for(int i = 0; i < n; i++){
      string name;
      cin >> name;
      int c = 0;
      while(cin.peek() != '\n' && cin.peek() != EOF){
        int t;
        cin >> t;
        if(t == k){
          v.push_back({c,name});
        }
        c++;
      }
    }
    
    sort(v.begin(), v.end());
    
    if(v.size() == 0){
      cout << -1;
      return 0;
    }
    
    int l = min(3, (int)v.size());
    
    for(int i = 0; i < l; i++){
      cout << v[i].second << " ";
    }
}