pub trait Kitamasa: Clone { fn zero() -> Self; fn one() -> Self; fn add(&self, rhs: &Self) -> Self; fn mul(&self, rhs: &Self) -> Self; } pub fn kitamasa_kth(c: &[T], mut k: usize) -> Vec { let n = c.len(); assert!(n > 0); let mul = |a: &[T], b: &[T]| -> Vec { let mut x = vec![T::zero(); a.len() + b.len() - 1]; for (i, a) in a.iter().enumerate() { for (x, b) in x[i..].iter_mut().zip(b) { *x = x.add(&a.mul(b)); } } for i in (n..x.len()).rev() { let v = x.pop().unwrap(); for (x, c) in x[(i - n)..].iter_mut().zip(c) { *x = x.add(&v.mul(c)); } } x }; let mut t = vec![T::one()]; let mut s = vec![T::zero(), T::one()]; while k > 0 { if k & 1 == 1 { t = mul(&t, &s); } s = mul(&s, &s); k >>= 1; } t.resize(n, T::zero()); t } fn read() -> (usize, Vec, Vec) { let mut s = String::new(); use std::io::Read; std::io::stdin().read_to_string(&mut s).unwrap(); let mut it = s.trim().split_whitespace(); let mut next = || it.next().unwrap().parse::().unwrap(); let k = next() as usize; let n = next() as usize; let a = (0..k).map(|_| next()).collect::>(); let b = (0..k).map(|_| next()).collect::>(); (n, a, b) } impl Kitamasa for i64 { fn zero() -> Self { std::i64::MIN } fn one() -> Self { std::i64::MAX } fn add(&self, rhs: &Self) -> Self { std::cmp::max(*self, *rhs) } fn mul(&self, rhs: &Self) -> Self { std::cmp::min(*self, *rhs) } } fn main() { let (n, a, b) = read(); let d = kitamasa_kth(&b, n); let ans = a.into_iter().zip(d).fold(std::i64::MIN, |s, p| s.max(p.0.min(p.1))); println!("{}", ans); }