Created
December 21, 2025 20:48
-
-
Save icub3d/8443350f20d2555d165a2f6078a3b5f4 to your computer and use it in GitHub Desktop.
Kattis zanzibar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::io::{Read, stdin}; | |
| fn main() { | |
| let mut s = String::new(); | |
| stdin().read_to_string(&mut s).unwrap(); | |
| for m in s.lines().skip(1) { | |
| let imports = m | |
| .split_whitespace() | |
| .map(|v| v.parse::<usize>().unwrap()) | |
| .filter(|&v| v != 0) | |
| .scan(None, |prev, cur| { | |
| let import = match *prev { | |
| Some(p) => cur.saturating_sub(2 * p), | |
| None => 0, | |
| }; | |
| *prev = Some(cur); | |
| Some(import) | |
| }) | |
| .sum::<usize>(); | |
| println!("{imports}"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment