use std::collections::{BTreeSet, HashSet}; use proconio::input; fn main() { input! { n:usize, m:usize, a:[usize;n], b:[usize;n], tc:[(usize,usize);m], } let mut c_t0 = tc .iter() .filter_map(|(t, c)| if *t == 0 { Some(*c) } else { None }) .collect::>(); c_t0.sort(); let mut c_t1 = tc .iter() .filter_map(|(t, c)| if *t == 1 { Some(*c) } else { None }) .collect::>(); c_t1.sort(); let mut bs = BTreeSet::new(); let mut unbuy = (0..m).collect::>(); let mut ids_sort = (0..n).collect::>(); ids_sort.sort_by_key(|i| a[*i]); let mut ans = 0; let mut id = 0; for &c in c_t0.iter() { while id < n && a[ids_sort[id]] <= c { bs.insert((b[ids_sort[id]], ids_sort[id])); id += 1; } if let Some(&last) = bs.last() { ans += 1; bs.remove(&last); unbuy.remove(&last.1); } } let mut b_rem = unbuy.iter().map(|i| b[*i]).collect::>(); b_rem.sort_by(|x, y| y.cmp(x)); for &c in c_t1.iter() { match b_rem.last() { Some(&last) if last <= c => { ans += 1; b_rem.pop(); } _ => (), } } ans = n - ans; println!("{}", ans); }