Skip to content

Instantly share code, notes, and snippets.

@icub3d
Created December 21, 2025 20:48
Show Gist options
  • Select an option

  • Save icub3d/438fb3c3f515173383d88f0eecd32e3f to your computer and use it in GitHub Desktop.

Select an option

Save icub3d/438fb3c3f515173383d88f0eecd32e3f to your computer and use it in GitHub Desktop.
Kattis speedlimit
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