Submission #1840063
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 init = 0;
let mut mid = xs[..k].iter().sum::<isize>();
let mut tail = xs[k..].iter().filter(|&&x|x.is_positive()).sum::<isize>();
let mut ans = std::cmp::max(0, mid) + tail;
for i in 0 .. n-k {
init += std::cmp::max(0, xs[i]);
mid = mid - xs[i] + xs[i+k];
tail -= std::cmp::max(0, xs[i+k]);
ans = std::cmp::max(ans, init + std::cmp::max(0, mid) + tail)
}
println!("{}", ans);
}
#[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 |
400 |
Code Size |
2838 Byte |
Status |
AC |
Exec Time |
12 ms |
Memory |
8444 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
400 / 400 |
Status |
|
|
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 |
AC |
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 |
AC |
2 ms |
4352 KB |
1_03.txt |
AC |
5 ms |
4352 KB |
1_04.txt |
AC |
12 ms |
8444 KB |
1_05.txt |
AC |
12 ms |
8444 KB |
1_06.txt |
AC |
11 ms |
6396 KB |
1_07.txt |
AC |
11 ms |
6396 KB |
1_08.txt |
AC |
11 ms |
8444 KB |
1_09.txt |
AC |
10 ms |
6396 KB |
1_10.txt |
AC |
10 ms |
6396 KB |
1_11.txt |
AC |
11 ms |
6396 KB |
1_12.txt |
AC |
10 ms |
6396 KB |
1_13.txt |
AC |
11 ms |
6396 KB |
1_14.txt |
AC |
10 ms |
6396 KB |
1_15.txt |
AC |
11 ms |
8444 KB |
1_16.txt |
AC |
11 ms |
6396 KB |
1_17.txt |
AC |
11 ms |
6396 KB |
1_18.txt |
AC |
11 ms |
6396 KB |
1_19.txt |
AC |
10 ms |
6396 KB |
1_20.txt |
AC |
10 ms |
6396 KB |
1_21.txt |
AC |
10 ms |
6396 KB |