Submission

Status:
[PPPPP][PPPPP]

Score: 100

User: Nozomi_boundfortokyo

Problemset: จุดแวะพัก

Language: cpp

Time: 0.027 second

Submitted On: 2025-03-19 23:12:44

#include <bits/stdc++.h>
using namespace std;
vector<pair<string,int>> before;
bool cmp(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()
{
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		string str;
		int cnt=0;
		int stop;
		bool stopatk=false;
		cin>>str;
		for(int j=0;;j++)
		{
			if(cin.peek()=='\n' || cin.peek()==EOF) break;
			cin>>stop;
			if(stop<k)
			{
				cnt++;
			}
			else if(stop==k)
			{
				stopatk=true;
			}
		}
		if(stopatk)
		{
		  before.push_back({str,cnt});	
		}
	}
	sort(before.begin(),before.end(),cmp);
	if(before.size()==0)
	{
		cout<<-1;
		return 0;
	}
	int si=before.size();
	for(int i=0;i<min(3,si);i++)
	{
		cout<<before[i].first<<' ';
	}
	
}