A - バスの出発時刻 / Bus Departure Time Editorial by admin
GPT 5.2 HighOverview
This problem asks you to find the last time someone boards the bus (the maximum \(T_i\)) and output the time \(K\) minutes after that.
Analysis
Takahashi gives the departure signal “exactly \(K\) minutes after the last student boards.” In other words, all we need to do is find the latest time among all boarding times \(T_1, T_2, \ldots, T_N\):
- Last boarding time \(= \max(T_i)\)
The departure signal time is obtained by adding \(K\) to that:
- Answer \(= \max(T_i) + K\)
For example, when \(T = [10, 3, 25]\) and \(K = 7\), the last student to board arrives at time \(25\), so the signal is at \(25 + 7 = 32\).
A straightforward approach to find “who is the last student” would be to sort the array and look at the last element, but sorting takes \(O(N\log N)\). Finding the maximum with a single pass takes only \(O(N)\), which is simpler.
Algorithm
- Read \(N, K\) and the array \(T\) as input.
- Find the maximum value \(M = \max(T)\).
- Output \(M + K\).
Complexity
- Time complexity: \(O(N)\) (since we find the maximum with a single pass)
- Space complexity: \(O(N)\) (to store the input array \(T\))
Implementation Notes
\(T_i\) can be up to \(10^9\), so depending on the language, be careful about integer type ranges (Python has no issue).
Since the input can have up to \(10^5\) elements, in Python using
sys.stdin.buffer.read()allows for faster input reading.Since we only need the maximum value, using
max(T)provides a concise implementation.Source Code
import sys
def main():
data = list(map(int, sys.stdin.buffer.read().split()))
N, K = data[0], data[1]
T = data[2:2+N]
print(max(T) + K)
if __name__ == "__main__":
main()
This editorial was generated by gpt-5.2-high.
posted:
last update: