use std::{collections::{HashMap, BinaryHeap, BTreeSet}, cmp::Reverse}; fn main() { let mut nk = String::new(); std::io::stdin().read_line(&mut nk).ok(); let nk: Vec = nk.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nk[0]; let k = nk[1]; let teams = (0..n).map(|_| { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); (temp[0], temp[1], temp[2]) }) .collect::>(); let mut mapping = HashMap::new(); for (i, &(s, p, u)) in teams.iter().enumerate() { mapping.entry(u).or_insert(BTreeSet::new()).insert((s, Reverse(p), i)); } let mut pque = BinaryHeap::new(); for (&u, btree) in mapping.iter() { for (i, &(s, _, idx)) in btree.iter().rev().enumerate() { pque.push((s, Reverse(i), idx)); } } for _ in 0..k { println!("{}", pque.pop().unwrap().2); } }