Submission #1839949


Source Code Expand

#[allow(unused_macros)]
macro_rules! debug {
  ($($e:expr), *) => {println!(concat!($(stringify!($e), " = {:?}\n"), *), $($e), *)}
}

fn main() {
  let (n, k) = get::tuple::<usize,usize>();
  let xs = get::list::<isize>();
  
  let mut mi = 0;
  let mut mj = k - 1;
  let mut acc = xs[0..k].iter().sum::<isize>();
  let mut max = acc;
  for a in 1 .. n {
    acc = acc - xs[a-1] + xs[(a+k-1)%n];
    if acc > max {
      max = acc;
      mi = a;
      mj = a + k - 1;
    }
  }
  
  let sum_rest = {
    if mj < n {
      let init = xs[..mi].iter().filter(|&&x|x.is_positive()).sum::<isize>();
      let tail = xs[mj+1..].iter().filter(|&&x|x.is_positive()).sum::<isize>();
      init + tail
    } else {
      xs[mj%n+1..mi].iter().filter(|&&x|x.is_positive()).sum::<isize>()
    }
  };
    
  println!("{}", max + sum_rest)
}

#[allow(dead_code)]
mod get {
  use std::io::*;
  use std::str::*;

  pub fn val<T: FromStr>() -> T {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().parse::<T>().ok().unwrap()
  }

  pub fn vals<T: FromStr>(n: usize) -> Vec<T> {
    let mut vec: Vec<T> = vec![];
    for _ in 0 .. n {
      vec.push(val());
    }
    vec
  }

  pub fn tuple<T1: FromStr, T2: FromStr>() -> (T1, T2) {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    let mut it = buf.trim_right().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    (x, y)
  }

  pub fn tuples<T1: FromStr, T2: FromStr>(n: usize) -> Vec<(T1, T2)> {
    let mut vec: Vec<(T1, T2)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple());
    }
    vec
  }

  pub fn tuple3<T1: FromStr, T2: FromStr, T3: FromStr>() -> (T1, T2, T3) {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    let mut it = buf.trim_right().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    let z = it.next().unwrap().parse::<T3>().ok().unwrap();
    (x, y, z)
  }

  pub fn tuple3s<T1: FromStr, T2: FromStr, T3: FromStr>(n: usize) -> Vec<(T1, T2, T3)> {
    let mut vec: Vec<(T1, T2, T3)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple3());
    }
    vec
  }

  pub fn list<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect()
  }

  pub fn lists<T: FromStr>(h: usize) -> Vec<Vec<T>> {
    let mut mat: Vec<Vec<T>> = vec![];
    for _ in 0 .. h {
      mat.push(list());
    }
    mat
  }

  pub fn chars() -> Vec<char> {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().chars().collect()
  }
}

Submission Info

Submission Time
Task B - Contiguous Repainting
User aimy
Language Rust (1.15.1)
Score 0
Code Size 3033 Byte
Status WA
Exec Time 13 ms
Memory 8444 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
WA × 1
AC × 10
WA × 16
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt
Case Name Status Exec Time Memory
0_00.txt AC 2 ms 4352 KB
0_01.txt AC 2 ms 4352 KB
0_02.txt WA 2 ms 4352 KB
0_03.txt AC 2 ms 4352 KB
1_00.txt AC 2 ms 4352 KB
1_01.txt AC 2 ms 4352 KB
1_02.txt WA 2 ms 4352 KB
1_03.txt AC 5 ms 4352 KB
1_04.txt AC 12 ms 8444 KB
1_05.txt WA 13 ms 8444 KB
1_06.txt AC 11 ms 6396 KB
1_07.txt AC 11 ms 6396 KB
1_08.txt WA 12 ms 8444 KB
1_09.txt AC 11 ms 6396 KB
1_10.txt WA 11 ms 6396 KB
1_11.txt WA 11 ms 6396 KB
1_12.txt WA 11 ms 6396 KB
1_13.txt WA 11 ms 6396 KB
1_14.txt WA 11 ms 6396 KB
1_15.txt WA 12 ms 8444 KB
1_16.txt WA 11 ms 6396 KB
1_17.txt WA 11 ms 6396 KB
1_18.txt WA 11 ms 6396 KB
1_19.txt WA 11 ms 6396 KB
1_20.txt WA 11 ms 6396 KB
1_21.txt WA 11 ms 6396 KB