use proconio::{input, marker::Usize1}; fn main() { input! { n:usize, k:Usize1, a:[usize;n], } let mut ps = vec![0; n]; let mut fi = 0; let mut bi = n - 1; let mut s = vec![]; for i in 0..n - 1 { s.push(i); if a[i] > a[i + 1] { while let Some(id) = s.pop() { ps[fi] = id; fi += 1; } } else if a[i] < a[i + 1] { while let Some(id) = s.pop() { ps[bi] = id; bi -= 1; } } } s.push(n - 1); while let Some(id) = s.pop() { ps[fi] = id; fi += 1; } for i in 0..n { if i == ps[k] { continue; } print!("{} ", a[i]); } println!() }