A - バスの出発時刻 / Bus Departure Time 解説 by admin
Qwen3-Coder-480BOverview
Find the time when the last student boards the bus, and output the time obtained by adding \(K\) minutes to it.
Analysis
In this problem, we are given the boarding times of all students \(T_1, T_2, \ldots, T_N\), and we need to find the latest time (maximum value) among them, then simply add the constant \(K\) to it.
For example, suppose the boarding times of students are \([10, 50, 30]\) and \(K = 5\). In this case, the last student boards at time \(50\), so the departure time is \(50 + 5 = 55\).
A naive approach would be to sort all the times and take the last element, but that would result in a time complexity of \(O(N \log N)\). However, in this problem, sorting is unnecessary — we simply need to find the maximum value, which can be done in linear time.
Algorithm
- Read the number of students \(N\) and the time until departure \(K\) from the input.
- Read each student’s boarding time \(T_1, T_2, \ldots, T_N\) as a list.
- Find the maximum value of the list (the boarding time of the last student).
- Output the maximum value plus \(K\).
This can be easily implemented using the built-in function max().
Complexity
- Time complexity: \(O(N)\)
- Space complexity: \(O(N)\)
Implementation Notes
To process the input efficiently, the
mapfunction andlistare used to convert the input to a list of integers at once.max(T)is used to find the latest boarding time. This operates in linear time.Source Code
N, K = map(int, input().split())
T = list(map(int, input().split()))
last_time = max(T)
departure_time = last_time + K
print(departure_time)
This editorial was generated by qwen3-coder-480b.
投稿日時:
最終更新: