Submission

Status:

[P-SSS][-SSSS]

Subtask/Task Score:

{0/50}{0/50}

Score: 0

User: nemuchannnUwU

Problemset: จุดแวะพัก

Language: cpp

Time: 0.014 second

Submitted On: 2026-03-11 13:10:18

#include<bits/stdc++.h>
using namespace std;
static bool sss(pair<string,int> &a,pair<string,int> &b){
	if (a.second==b.second) return a.first<b.first;
	return a.second<b.second;
}
int main(){
	cin.tie(nullptr)->sync_with_stdio();
	vector<pair<string,int>> ans;
	int n,k; cin >> n >> k;
	cin.ignore();
	while(n--){
		string s;
		getline(cin,s);
		stringstream ss(s);
		string word;
		int i=0,cnt=0;
		bool found=false;
		string temp;
		while(ss>>word){
			if (i==0){
				temp=word;
			}else{
				int a=stoi(word);
				if (a==k){
					found=true;
				}else if(!found){
					cnt++;
				}
			}
			i++;
		}
		if (found)
			ans.push_back({temp,cnt});
	}
	sort(ans.begin(),ans.end(),sss);
	for (auto &p : ans){
		cout << p.first << " ";
	}
}