USACO Bronze 2015 December - Speeding

Authors: Jesse Choe, Kevin Sheng, Maggie Liu, Rameez Parwez

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.

C++

Implementation

#include <bits/stdc++.h>
using namespace std;
const int LEN = 100;
int main() {
freopen("speeding.in", "r", stdin);
freopen("speeding.out", "w", stdout);
int N, M;

Java

import java.io.*;
import java.util.*;
public class Speeding {
private static final int LEN = 100;
public static void main(String[] args) throws IOException {
BufferedReader read = new BufferedReader(new FileReader("speeding.in"));
StringTokenizer initial = new StringTokenizer(read.readLine());
int roadSegNum = Integer.parseInt(initial.nextToken());
int bessieSegNum = Integer.parseInt(initial.nextToken());

Python

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!