use std::io::stdin; const INF: usize = 1000000000; fn f(sa: usize, sb: usize, x: &[usize], a: &[usize], b: &[usize], m: usize) -> usize { let mut two = 0; let mut three = 0; for (&xi, (&ai, &bi)) in x.into_iter().zip(a.into_iter().zip(b.into_iter())) { let mut solved = 0; solved += xi; if ai >= sa { solved += 1; } if bi >= sb { solved += 1; } if solved >= 2 { two += 1 } if solved >= 3 { three += 1 } } if two < m { INF } else { three } } fn main() { let mut input = stdin().lines().map(|s| s.unwrap()); let s = input.next().unwrap(); let mut s = s.split_whitespace(); let n: usize = s.next().unwrap().parse().unwrap(); let m: usize = s.next().unwrap().parse().unwrap(); let mut x = Vec::with_capacity(n); let mut a = Vec::with_capacity(n); let mut b = Vec::with_capacity(n); for line in input.take(n) { let mut line = line.split_whitespace(); let xi: usize = line.next().unwrap().parse().unwrap(); let ai: usize = line.next().unwrap().parse().unwrap(); let bi: usize = line.next().unwrap().parse().unwrap(); x.push(xi); a.push(ai); b.push(bi); } let mut res = INF; let mut sb = 100001; for sa in 0..100002 { let mut t = f(sa, sb, &x, &a, &b, m); while t == INF && sb > 0 { sb -= 1; t = f(sa, sb, &x, &a, &b, m); } res = res.min(t); } println!("{}", res); }