use proconio::input; fn main() { input! { n: usize, h: usize, ab: [(usize, usize); n], } let mut memo = vec![0; h + 1]; let mut cnt = 0; for &(a, b) in &ab { if b - a > h / 2 { for j in 0..a { memo[j] -= 1; } for j in b + 1..=h { memo[j] -= 1; } cnt += 1; } else { for i in a..=b { memo[i] += 1; } } } println!("{}", memo.iter().max().unwrap() + cnt); }