結果

問題 No.3684 chokudai_niku.png
コンテスト
ユーザー norioc
提出日時 2026-09-22 16:30:56
言語 Rust
(1.97.1 + proconio + num + itertools + ACL)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
AC  
実行時間 18 ms / 2,000 ms
+ 198µs
コード長 1,812 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,019 ms
コンパイル使用メモリ 192,788 KB
実行使用メモリ 11,528 KB
最終ジャッジ日時 2026-09-22 16:31:06
合計ジャッジ時間 9,797 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 44
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#![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<i64>
}

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<R>(&self, range: R) -> i64
    where
        R: RangeBounds<usize>
    {
        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);
}
0