Submission

Status:
[PPPPP][PPPPP]

Score: 100

User: devilpoohs

Problemset: จุดแวะพัก

Language: cpp

Time: 0.008 second

Submitted On: 2025-03-23 12:03:39

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

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


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,tar;
    cin>>n>>tar;
    bool chk;
    cin.ignore();
    string input;
    int count;
    int a;
    string name;
    vector<pair<string,int>> ar;
    for(int i=0;i<n;i++){
        getline(cin,input);
        stringstream ss(input);
        count=0;
        chk=false;
        ss>>name;
        while(ss>>a){
            if(a<tar){
                count++;
            }
            if(a==tar){
                chk=true;
            }
            
        }
        if(chk){
            ar.push_back({name,count});
        }


    }
    sort(ar.begin(),ar.end(),comp);
    if(ar.empty()){
        cout<<-1;
    }else{
        int n=ar.size();
        for(int i=0;i<3 and i<n;i++){
            cout<<ar[i].first<<' ';
        }
    }
}