use std::{collections::BinaryHeap, 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 items = (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]-1) }) .collect::>(); let mut mapping = vec![vec![]; 100000]; for i in 0..n { let (s, p, u) = items[i]; mapping[u].push(i); } let mut pque = BinaryHeap::new(); for i in 0..100000 { mapping[i].sort_by_key(|&i| (Reverse(items[i].0), items[i].1)); for (idx, &j) in mapping[i].iter().enumerate() { let (s, p, _) = items[j]; pque.push((s, Reverse(idx), Reverse(p), j)); } } for _ in 0..k { println!("{}", pque.pop().unwrap().3); } }