Created
January 20, 2026 16:17
-
-
Save icub3d/f6958d4e997caf66125830e6e0d93c4f to your computer and use it in GitHub Desktop.
Kattis climbingstairs
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(); | |
| let mut ss = s.split_whitespace().map(|v| v.parse::<isize>().unwrap()); | |
| let n = ss.next().unwrap(); | |
| let r = ss.next().unwrap(); | |
| let k = ss.next().unwrap(); | |
| let to_desk = k + (r - k).abs(); | |
| // If we've walked n, we are done. | |
| // Otherwise we need to walk more steps but can only do it in pairs of 2. | |
| let total = match to_desk < n { | |
| true => to_desk + ((n - to_desk + 1) / 2) * 2 + r, | |
| false => to_desk + r, | |
| }; | |
| println!("{total}"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment