Submission

Status:
[PPPPP][-SSSS]

Score: 50

User: MiyaZaki1072

Problemset: จุดแวะพัก

Language: cpp

Time: 0.005 second

Submitted On: 2025-04-15 16:03:40

#include <bits/stdc++.h>
using namespace std;
struct A{
    string name;
    int v;
    bool operator<(const A&o)const{
        if(v!=o.v)return v<o.v;
        return name < o.name;
    }
};
vector<A>ans;
int main(){
    cin.tie(0)->sync_with_stdio(0);
    int n,k;cin>>n>>k;
    cin.ignore();
    for(int i=1;i<=n;i++){
        string a;
        getline(cin,a);
        int cnt = 0,v=-1;
        string tmp="",nm;
        for(auto &x:a){
            if(x == ' '){
                if(cnt==0)nm = tmp;
                else{
                    int rn = stoi(tmp);
                    if(rn == k)v=cnt;
                }
                cnt++;
                tmp="";
            }
            else tmp.push_back(x);
        }
        int rn = stoi(tmp);
        if(rn == k)v=cnt;
        if(v!=-1)ans.push_back({nm,v});
    }
    sort(ans.begin(),ans.end());
    if(ans.size()==0)cout<<"-1";
    for(auto &x:ans)cout<<x.name<<" ";
}