Created
December 21, 2025 20:48
-
-
Save icub3d/438fb3c3f515173383d88f0eecd32e3f to your computer and use it in GitHub Desktop.
Kattis speedlimit
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 lines = s.lines(); | |
| while let Some(line) = lines.next() { | |
| let n = match line.parse::<usize>() { | |
| Ok(n) => n, | |
| Err(_) => break, | |
| }; | |
| let dist = lines | |
| .by_ref() | |
| .take(n) | |
| .scan(0, |prev, line| { | |
| let (speed, duration) = line | |
| .split_once(' ') | |
| .map(|(l, r)| (l.parse::<usize>().unwrap(), r.parse::<usize>().unwrap())) | |
| .unwrap(); | |
| let cur = duration - *prev; | |
| *prev = duration; | |
| Some(speed * cur) | |
| }) | |
| .sum::<usize>(); | |
| println!("{} miles", dist); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment