#![allow(non_snake_case, unused_imports)] use std::collections::{BinaryHeap, Bound, HashMap, HashSet, VecDeque}; use std::ops::RangeBounds; use ac_library::{Additive, Min, Segtree}; use proconio::{input, marker::Usize1, marker::Chars}; use itertools::Itertools; #[allow(unused_macros)] macro_rules! d { ( $( $x:expr ),* $(,)? ) => { eprintln!( concat!( $( stringify!($x), "={:?} " ),* ), $( $x ),* ); }; } #[allow(dead_code)] fn yn(b: bool) -> &'static str { if b { "Yes" } else { "No" } } #[derive(Debug)] struct Accum { acc: Vec } impl Accum { fn new(xs: &[i64]) -> Self { let acc = xs.iter() .scan(0, |s, &x| { *s += x; Some(*s) }) .collect_vec(); Self { acc } } fn range_sum(&self, range: R) -> i64 where R: RangeBounds { let n = self.acc.len(); let l = match range.start_bound() { Bound::Included(&x) => x, Bound::Excluded(&x) => x+1, Bound::Unbounded => 0, }; let r = match range.end_bound() { Bound::Included(&x) => x, Bound::Excluded(&x) => x-1, Bound::Unbounded => n-1, }; assert!(l <= r); assert!(r <= n-1); self.acc[r] - if l > 0 { self.acc[l-1] } else { 0 } } } fn main() { input! { N: usize, M: usize, A: [i64; N], B: [i64; N], } let xs = A.iter() .zip(B.iter()) .map(|(a, b)| (a-b).max(0)) .collect_vec(); let accum = Accum::new(&xs); let mut ans = 0; for i in 0..N { if i+M > N { break } ans = ans.max(accum.range_sum(i..i+M)); } println!("{}", ans); }