https://atcoder.jp/contests/abc267/tasks/abc267_c
どうしてもusizeとi64の変換が必要な問題なのでめんどうですね。
// Index × A(Continuous ver.) #![allow(non_snake_case)] use std::cmp::max; fn read<T: std::str::FromStr>() -> T { let mut line = String::new(); std::io::stdin().read_line(&mut line).ok(); line.trim().parse().ok().unwrap() } fn read_vec<T: std::str::FromStr>() -> Vec<T> { read::<String>().split_whitespace() .map(|e| e.parse().ok().unwrap()).collect() } fn max_sum(M: usize, A: &Vec<i64>) -> i64{ let N = A.len(); let mut T: i64 = (0..M).map(|i| A[i]).sum(); let mut S = (0..M).map(|i| ((i+1) as i64)*A[i]).sum(); let mut m = S; for i in 1..(N-M+1) { S = S - T + (M as i64) * A[i+M-1]; m = max(m, S); if i != N - M { T = T - A[i-1] + A[i+M-1] } } return m } fn main() { let v = read_vec(); let M = v[1]; let A = read_vec(); println!("{}", max_sum(M, &A)) }