Submission

Status:

[P-SSS][PPP-S]

Subtask/Task Score:

{0/50}{0/50}

Score: 0

User: RINRPTM

Problemset: จุดแวะพัก

Language: cpp

Time: 0.014 second

Submitted On: 2026-10-03 13:34:32

#include<iostream>
#include<queue>
#include<sstream>
using namespace std;
struct cmd{
    bool operator()( 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;
    cin.ignore();
    priority_queue<pair<string,int>,vector<pair<string,int>>,cmd> pq;
    while(n--){
        string s;
        getline(cin,s);
        stringstream ss(s);
        string v;
        string name;
        int x = 0;
        bool find = false;
        while(ss>>v){
            if(isalpha(v[0])){
                name = v;
            }else{
                x++;
                int a = stoi(v);
                if(a == k){
                    find = true;
                    break;
                }
            }
        }
        if(find){
            pq.push(make_pair(name,x));
        }
    }
    for(int i = 0;i<3;i++){
        if(pq.empty() == 0){
            cout << pq.top().first << ' ';
            pq.pop();
        }
    }
}