pub trait SemiRing: Clone { fn zero() -> Self; fn one() -> Self; fn add(&self, rhs: &Self) -> Self; fn mul(&self, rhs: &Self) -> Self; } pub struct Kitamasa { c: Vec, tmp: std::cell::RefCell>, } impl Kitamasa { pub fn new(c: Vec) -> Self { assert!(!c.is_empty()); Self { c: c, tmp: std::cell::RefCell::new(vec![]), } } pub fn normalize(&self, d: &mut Vec) { let n = self.c.len(); for i in (n..d.len()).rev() { let v = d.pop().unwrap(); for (d, c) in d[(i - n)..].iter_mut().zip(&self.c) { *d = d.add(&v.mul(c)); } } } pub fn next(&self, d: &mut Vec) { d.insert(0, T::zero()); self.normalize(d); } pub fn twice(&self, d: &mut Vec) { assert!(!d.is_empty()); let mut tmp = self.tmp.borrow_mut(); tmp.clear(); tmp.resize(d.len() * 2 - 1, T::zero()); for (i, a) in d.iter().enumerate() { for (tmp, b) in tmp[i..].iter_mut().zip(d.iter()) { *tmp = tmp.add(&a.mul(b)); } } std::mem::swap(&mut *tmp, d); drop(tmp); self.normalize(d); } pub fn kth_coefficient(&self, k: usize) -> Vec { let mut t = vec![T::one()]; if k > 0 { let p = (k + 1).next_power_of_two().trailing_zeros() - 1; for i in (0..=p).rev() { self.twice(&mut t); if k >> i & 1 == 1 { self.next(&mut t); } } } t.resize(self.c.len(), 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 SemiRing 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 solver = Kitamasa::new(b); let d = solver.kth_coefficient(n); let ans = a.into_iter().zip(d).fold(std::i64::MIN, |s, p| s.max(p.0.min(p.1))); println!("{}", ans); }