#![allow(unused_imports)] fn main() { input! { n: usize, k: usize, a: [usize; n], b: [usize; n], } let a = a .into_iter() .map(|a| { (1..) .take_while(|i| i * i <= a) .flat_map(|i| { if a.is_multiple_of(i) { vec![i, a / i] } else { vec![] } }) .sorted() .collect_vec() }) .collect_vec(); let (mut ok, mut ng) = (0usize, 100_000 + 1); while ok.abs_diff(ng) > 1 { let mid = (ok + ng) / 2; let mut sum = 0usize; for (a, &b) in izip!(&a, &b) { let mut cnt = usize::MAX; for &d in a { if d >= mid { chmin!(cnt, b.div_ceil(d) * d - b); } } sum = sum.saturating_add(cnt); } *if sum <= k { &mut ok } else { &mut ng } = mid; } println!("{ok}"); } use itertools::{Itertools as _, iproduct, izip}; use proconio::{input, marker::*}; use std::{cmp::Reverse, collections::*}; #[macro_export] macro_rules! chmax { ($a:expr, $b:expr) => {{ let tmp = $b; if $a < tmp { $a = tmp; true } else { false } }}; } #[macro_export] macro_rules! chmin { ($a:expr, $b:expr) => {{ let tmp = $b; if $a > tmp { $a = tmp; true } else { false } }}; } #[macro_export] /// mvec![] macro_rules! mvec { ($val:expr; ()) => { $val }; ($val:expr; ($size:expr $(,$rest:expr)*)) => { vec![mvec![$val; ($($rest),*)]; $size] }; }