Official Analysis (Java)

Video Solution

By Maggie Liu

Video Solution Code

Explanation

Since the road is only 100 miles long, we can store the speed limit as well as Bessie's speed for each mile separately.

Once we have the speeds, our final answer is the maximum difference between the Bessie's speed and speeding limit across all 100 miles.

with open("speeding.in") as read:
road_seg_num, speed_seg_num = [int(i) for i in read.readline().split()]
limit_segs = [
[int(i) for i in read.readline().split()] for _ in range(road_seg_num)
]
bessie_segs = [
[int(i) for i in read.readline().split()] for _ in range(speed_seg_num)
]

Join the USACO Forum!

Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!