2020 Jan Bronze Problem 3 Race
Jump to navigation
Jump to search
Official Problem Statement[edit]
Problem statement:
In the Race problem, you are given a sequence of N (1 ≤ N ≤ 10,000) horses, each with a speed Si (1 ≤ Si ≤ 1,000,000). You must determine the minimum time it takes for all the horses to cross the finish line.
Solution:
The solution to this problem is to find the maximum speed among all the horses. This can be done by iterating through the sequence of horses and keeping track of the maximum speed seen so far. Once the maximum speed is found, the minimum time it takes for all the horses to cross the finish line is simply the maximum speed divided by the total number of horses.
In C++, this can be implemented as follows:
int N; // number of horses int S[10000]; // speeds of horses int maxSpeed = 0; for (int i = 0; i < N; i++) { maxSpeed = max(maxSpeed, S[i]); } double minTime = (double) maxSpeed / N;