Submission #1384166
Source Code Expand
use std::io; use std::cmp::max; use std::collections::VecDeque; fn main() { let mut input = Input::new(); let n: usize = input.next(); let k: usize = input.next(); let a: Vec<i64> = (0..n).map(|_| input.next()).collect(); let mut s: i64 = 0; let mut nm: i64 = 0; let mut bm: i64 = i64::min_value(); let mut np: i64 = 0; let mut bp: i64 = i64::max_value(); for i in 0..n { if a[i] > 0 { s += a[i]; np += a[i]; } else { nm += a[i]; } if i >= k { if a[i - k] > 0 { np -= a[i - k]; } else { nm -= a[i - k]; } } if i + 2 > k { if bm < nm { bm = nm; } if bp > np { bp = np; } } } println!("{}", max(s + bm, s - bp)); } struct Input { queue: VecDeque<String>, } impl Input { fn new() -> Input { Input { queue: VecDeque::new() } } fn next<T>(&mut self) -> T where T: std::str::FromStr, T::Err: std::fmt::Debug { if self.queue.is_empty() { let mut line = String::new(); let _ = io::stdin().read_line(&mut line); for x in line.split_whitespace() { self.queue.push_back(String::from(x)); } } return self.queue.pop_front().unwrap().parse::<T>().unwrap(); } }
Submission Info
Submission Time | |
---|---|
Task | B - Contiguous Repainting |
User | hoshi524 |
Language | Rust (1.15.1) |
Score | 400 |
Code Size | 1546 Byte |
Status | AC |
Exec Time | 19 ms |
Memory | 12324 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 | 12 ms | 10492 KB |
1_04.txt | AC | 18 ms | 12324 KB |
1_05.txt | AC | 19 ms | 12324 KB |
1_06.txt | AC | 18 ms | 11768 KB |
1_07.txt | AC | 18 ms | 11768 KB |
1_08.txt | AC | 18 ms | 12296 KB |
1_09.txt | AC | 18 ms | 11768 KB |
1_10.txt | AC | 18 ms | 12024 KB |
1_11.txt | AC | 18 ms | 12024 KB |
1_12.txt | AC | 17 ms | 12024 KB |
1_13.txt | AC | 18 ms | 11768 KB |
1_14.txt | AC | 17 ms | 11768 KB |
1_15.txt | AC | 19 ms | 12300 KB |
1_16.txt | AC | 18 ms | 11768 KB |
1_17.txt | AC | 17 ms | 11768 KB |
1_18.txt | AC | 18 ms | 11768 KB |
1_19.txt | AC | 17 ms | 11768 KB |
1_20.txt | AC | 18 ms | 12024 KB |
1_21.txt | AC | 18 ms | 11768 KB |