It is the final leg of the most famous amazing race. The top 'n' competitors have made…
- User
It is the final leg of the most famous amazing race. The top 'n' competitors have made it to the final. The final race has just begun. The race has 'm' checkpoints. Each team can reach any of the 'm' checkpoint but after a team reaches a particular checkpoint that checkpoint gets closed and is not open to any other team. The race ends when 'k' teams finish the race. Each team travel at a constant speed throughout the race which might be different for different teams. Given the coordinates of n teams and m checkpoints and speed of individual team return the value of minimum time needed to end the race.
NOTE:
The time required for a team at coordinate (p,q) with speed 's' to reach a checkpoint at coordinate (x,y) is given by:
t = ceil( ((p-x)^2 + (q-y)^2) / s^2 ). For example if distance is 5 units and speed is 2 units then required time = ceil(25/4) = 7. Input Format:
The first line contains 3 integers n, m and k denoting the total number of competitors, total number of checkpoints and the minimum number of teams that must complete the race in order to end the race.
This is followed by n lines each indicating the coordinates of n teams.
This is followed by m lines each indicating the coordinates of m checkpoints.
This is followed by n integers each denoting the speed of the ith team
Output Format:
Print the minimum time required to end the race.
Constraints:
1 ≤ n ≤ 200
1 ≤ m ≤ 200
1 ≤ k ≤ n
0 ≤ x coordinate of team and checkpoint ≤10^6
0 ≤ y coordinate of team and checkpoint ≤10^6
1 ≤ speed of team ≤ 50
SAMPLE INPUT 2 3 1 0 1 0 0 0 10 27 29 458 9651 5 3
SAMPLE OUTPUT 4
Explanation
For the race to finish in the minimum time the team at location (0,1) can reach the checkpoint at (0,10) .The distance between them is 9 and speed of team is 5 so required time is ceil(99))/(55))=ceil(81/25)=4.
Assistant
import math def max_bipartite_matching(adj, n_teams, m_checkpoints): match_to = [-1] * m_checkpoints # checkpoint j is matched to team def dfs(u, visited): for v in adj[u]: if not visited[v]: visited[v] = True if match_to[v] == -1 or dfs(match_to[v], visited): match_to[v] = u return True return False result = 0 for u in range(n_teams): visited = [False] * m_checkpoints if dfs(u, visited): result += 1 return result n, m, k = map(int, input().split()) teams = [tuple(map(int, input().split())) for _ in range(n)] checkpoints = [tuple(map(int, input().split())) for _ in range(m)] speeds = list(map(int, input().split())) # Precompute all team-checkpoint times computed_times = [] for i in range(n): x1, y1 = teams[i] s = speeds[i] row = [] for (x2, y2) in checkpoints: dx = x1 - x2 dy = y1 - y2 dist_sq = dx * dx + dy * dy speed_sq = s * s time = math.ceil(dist_sq / speed_sq) if speed_sq != 0 else 0 row.append(time) computed_times.append(row) # Collect unique times and sort all_times = set() for i in range(n): for j in range(m): all_times.add(computed_times[i][j]) sorted_times = sorted(all_times) low, high = 0, len(sorted_times) - 1 answer = sorted_times[-1] if sorted_times else 0 while low <= high: mid = (low + high) // 2 current_T = sorted_times[mid] adj = [[] for _ in range(n)] for i in range(n): for j in range(m): if computed_times[i][j] <= current_T: adj[i].append(j) matching = max_bipartite_matching(adj, n, m) if matching >= k: answer = current_T high = mid - 1 else: low = mid + 1 print(answer)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.