#![allow(non_snake_case)] #[allow(unused_imports)] use proconio::{fastout, input, marker::*}; #[fastout] fn main() { input! { N: usize, K: usize, A: [usize; K], } let mut B = A .iter() .cloned() .collect::>(); for a in A.iter() { B.insert(a + 2 * N); } let mut ok = 1; let mut ng = N + 1; while ng - ok > 1 { let m = (ok + ng) / 2; let mut nxt = vec![0u32; 4 * N + 1]; nxt[4 * N] = 4 * N as u32; for i in (0..4 * N).step_by(2) { // i + m がok か if i + m < 4 * N && B.range(i + 1..i + m).next().is_some() { nxt[i] = if m % 2 == 0 { (i + m) as u32 } else { (i + m + 1) as u32 }; } else { let n = B.range(i + m..).next(); if let Some(&n) = n { nxt[i] = (n + 1) as u32; } else { nxt[i] = (4 * N) as u32; } } } // eprintln!( // "{} | {}", // m, // nxt.iter() // .map(|x| x.to_string()) // .collect::>() // .join(" ") // ); let dbl = Doubling::build(&nxt, 22); let mut isok = false; for i in (0..2 * N).step_by(2) { let n = dbl.next(i as u32, K as u64); if n <= (i + 2 * N) as u32 { isok = true; break; } } if isok { ok = m; } else { ng = m; } } println!("{}", ok); } pub type Index = u32; pub struct Doubling { dp: Vec, pub size: usize, pub depth: Index, } impl Doubling { pub fn build(nxt: &[Index], depth: Index) -> Self { let size = nxt.len(); let mut dp = nxt.to_vec(); dp.append(&mut vec![0; size * depth as usize]); for d in 0..depth as usize { for i in 0..size { dp[(d + 1) * size + i] = dp[d * size + dp[d * size + i] as usize]; } } Self { dp, size, depth } } pub fn next(&self, mut src: Index, k: u64) -> Index { assert!(k < 1 << (self.depth + 1)); for i in 0..self.depth { if (k >> i) & 1 == 1 { src = self.dp[i as usize * self.size + src as usize]; } } src } pub fn jump_power_of_two(&self, src: Index, k: Index) -> Index { assert!(k <= self.depth); self.dp[k as usize * self.size + src as usize] } }