Submission

Status:
[PPPPP][PPPPP]

Score: 100

User: mydKN

Problemset: จุดแวะพัก

Language: cpp

Time: 0.003 second

Submitted On: 2025-03-23 13:46:32

// #include<bits/stdc++.h>

// using namespace std;

// using psi = pair<string, int>;

// const int inf = 2e9;

// int n, k;
// vector<psi> vec;

// bool comp(const psi& a, const psi& b){
//     if(a.second == b.second){
//         return a.first < b.first;
//     }
//     return a.second < b.second;
// }

// int main(){
//     ios_base::sync_with_stdio(0);cin.tie(0);
//     cin >> n >> k;
//     cin.ignore();
//     for(int i=0;i<n;++i){
//         string str, name;
//         getline(cin, str);
//         stringstream ss(str);
//         ss>>name;
//         int camp, cnt = 0;
//         while(ss>>camp){
//             if(camp == k){
//                 vec.emplace_back(name, cnt);
//                 break;
//             }
//             ++cnt;
//         }
//     }
//     if(!vec.size()){
//         cout << -1;
//         return 0;
//     }
//     sort(vec.begin(), vec.end(), comp);
//     for(int i=0;i<3 && i<vec.size();++i){
//         cout << vec[i].first << " ";
//     }
// }

#include<bits/stdc++.h>

using namespace std;

using psi = pair<string, int>;

const int inf = 2e9;

int n, k;
vector<psi> vec;

bool comp(const psi& a, const psi& b){
    if(a.second == b.second){
        return a.first < b.first;
    }
    return a.second < b.second;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> k;
    for(int i=0;i<n;++i){
        string name;
        cin >> name;
        string str;
        getline(cin, str);
        int cnt = 1;
        int val = 0;
        int camp = 0;
        int found = inf;
        for(int j=str.length()-1;j>=0;--j){
            if(str[j] != ' '){
                val += ((str[j] - '0') * cnt);
                cnt *= 10;
                ++camp;
            }
            else{
                if(val == k){
                    found = camp;
                }
                val = 0;
                cnt = 1;
            }
        }
        if(found != inf){
            found = camp - found + 1;
            vec.emplace_back(name, found);
        }
        // cout << found << "\n";
        // cout << name << str << "\n";
    }
    if(!vec.size()){
        cout << -1;
        return 0;
    }
    sort(vec.begin(), vec.end(), comp);
    for(int i=0;i<3 && i<vec.size();++i){
        cout << vec[i].first << " ";
    }
}