Submission

Status:

[PP-SS][-SSSS]

Subtask/Task Score:

{0/50}{0/50}

Score: 0

User: tha_smith

Problemset: จุดแวะพัก

Language: cpp

Time: 0.007 second

Submitted On: 2026-03-03 16:06:38

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

bool comp(const pair<int,string>& a, const pair<int,string>& b) {
    if (a.first == b.first) return a.second < b.second;
    return a.first < b.first;
}

int main() {
	ios_base::sync_with_stdio(0),cin.tie(0);
	int N,K; vector<pair<int,string>> m;
	cin >> N >> K;
	for(int i=0; i<N; i++) {
		string s, name, num=""; bool nus=0,rest=0; int count=0;
		cin >> name;
		getline(cin,s);
		for(int j=0; j<s.size(); j++) {
			if(s[j]!=' ') {
				num+=s[j];
				nus=1;
			}
			if((nus && s[j]==' ') || (nus && (j==s.size()-1))) {
				int NUM = stoi(num);
				//cout << name << ' ' << NUM << '\n';
				if(s[j]==' ' && nus && NUM!=K) {
					count++;
					num="";
					nus=0;
				}
				else if(NUM==K) {
					rest=1;
					num="";
					nus=0;
				}
			}	
		}
		if(rest) 
			m.push_back({count,name});
		//cout << count << ' ' << name << ' ' << rest << '\n';
	}
	if(m.empty()) {
		cout << -1;
		return 0;
	}
	sort(m.begin(),m.end(),comp);
	for(int i=0; i<m.size()&&i<3; i++) {
		cout << m[i].second << ' ';
	}
}