Submission
Status:
[PTSSS][-SSSS]
Subtask/Task Score:
{0/50}{0/50}
Score: 0
User: Seng
Problemset: จุดแวะพัก
Language: cpp
Time: 1.088 second
Submitted On: 2026-06-04 14:25:41
#include <bits/stdc++.h>
using namespace std;
using pis = pair<int, string>;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int n, k;cin >> n >> k;
int cnt_str = 0;
string str;cin >> str;//cin string
cnt_str++;
string str2 = str;
vector<vector<string>> v(k);
int ss = 0;
str = str2;
int x = 0, cnt = 0;
cin >> x;//cin num
while(cnt_str < n){
if(x < k) cnt++;
else if(x == k){
v[cnt].push_back(str);
ss++;
}
cin >> str2;
if('9' - str2[0] < 0){
cnt_str++;
str = str2;
cnt = 0;
cin >> x;
}
else x = stoi(str2);
}
while(x < k){
cnt++;
cin >> x;
}
if(x == k){
v[cnt].push_back(str);
ss++;
}
ss = min(3, ss);
for(int i = 0; i < k; i++){
if(ss == 0) break;
if(v[i].size() == 0) continue;
if(v[i].size() > 1){
sort(v[i].begin(), v[i].end());
for(auto e : v[i]){
cout << e << " ";
ss--;
if(ss == 0) break;
}
}
else cout << v[i][0] << " ";
}
if(ss == 0) cout << "-1";
}