Submission

Status:
[-SSSS][-SSSS]

Score: 0

User: devilpoohs

Problemset: จุดแวะพัก

Language: cpp

Time: 0.009 second

Submitted On: 2025-03-23 11:52:26

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

struct comp{
    bool operator()(pair<string,int> a,pair<string,int> b){
        return a.second>b.second;
    }
};  

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,tar;
    cin>>n>>tar;
    string input;
    priority_queue<pair<string,int>,vector<pair<string,int>>,comp> v;
    string name;
    int count;
    int a;
    bool chk;
    for(int i=0;i<n;i++){
        cin.ignore();
        getline(cin,input);
        
        count=0;
        stringstream ss(input);
        chk=false;
        ss>>name;
        while(ss>>a){
            if(a<tar){
                count++;
            }
            if(a==tar){
                chk=true;
            }
        }
        
        if(chk){
            v.push({name,count});
        }
        
    }
    int i=0;
    if(v.empty()){
        cout<<-1;
        return 0;
    }else{
        while(!v.empty() and i<=3){
            cout<<v.top().first<<' ';
            i++;
            v.pop();
        }
    }   
    return 0;
}