/
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 233 点
問題文
高橋君は、あるバス停の時刻表を分析しています。
このバス停には 1 日の間にちょうど N 本のバスが到着します。各バスの到着時刻は、1 日の開始時点(午前 0 時)を 0 秒として、0 以上 86400 以下の整数(秒)で記録されています。
N 本のバスの到着時刻は T_1, T_2, \ldots, T_N として時刻の早い順に与えられ、同じ時刻に 2 本以上のバスが到着することはありません(すなわち T_1 < T_2 < \cdots < T_N です)。
高橋君は、時刻順で連続する 2 本のバスの到着間隔をすべて求め、その中で最も短い間隔と最も長い間隔を知りたいと思っています。具体的には、i 番目と i+1 番目のバスの到着間隔を T_{i+1} - T_i(秒)と定義します(1 \leq i \leq N-1)。
これら N-1 個の到着間隔のうち、最小値と最大値をそれぞれ求めてください。
制約
- 2 \leq N \leq 2 \times 10^5
- 0 \leq T_i \leq 86400
- T_1 < T_2 < \cdots < T_N
- 入力はすべて整数である。
入力
N T_1 T_2 \ldots T_N
- 1 行目には、バスの本数を表す整数 N が与えられる。
- 2 行目には、各バスの到着時刻を表す N 個の整数 T_1, T_2, \ldots, T_N が、スペース区切りで与えられる。T_i は i 番目に到着するバスの到着時刻(秒)を表す。
出力
到着間隔の最小値と最大値を、スペース区切りで 1 行に出力せよ。
入力例 1
5 100 200 500 700 800
出力例 1
100 300
入力例 2
3 0 43200 86400
出力例 2
43200 43200
入力例 3
10 60 120 300 1800 3600 7200 36000 72000 80000 86400
出力例 3
60 36000
Score : 233 pts
Problem Statement
Takahashi is analyzing the timetable of a certain bus stop.
Exactly N buses arrive at this bus stop during one day. The arrival time of each bus is recorded as an integer (in seconds) between 0 and 86400 inclusive, where 0 represents the start of the day (midnight, 12:00 AM).
The arrival times of the N buses are given as T_1, T_2, \ldots, T_N in chronological order, and no two or more buses arrive at the same time (that is, T_1 < T_2 < \cdots < T_N).
Takahashi wants to find all the intervals between consecutive buses in chronological order, and determine the shortest and longest intervals among them. Specifically, the interval between the i-th and (i+1)-th buses is defined as T_{i+1} - T_i (seconds) (1 \leq i \leq N-1).
Find the minimum and maximum values among these N-1 intervals.
Constraints
- 2 \leq N \leq 2 \times 10^5
- 0 \leq T_i \leq 86400
- T_1 < T_2 < \cdots < T_N
- All input values are integers.
Input
N T_1 T_2 \ldots T_N
- The first line contains an integer N representing the number of buses.
- The second line contains N integers T_1, T_2, \ldots, T_N separated by spaces, representing the arrival times of each bus. T_i represents the arrival time (in seconds) of the i-th bus to arrive.
Output
Print the minimum and maximum values of the intervals, separated by a space, on one line.
Sample Input 1
5 100 200 500 700 800
Sample Output 1
100 300
Sample Input 2
3 0 43200 86400
Sample Output 2
43200 43200
Sample Input 3
10 60 120 300 1800 3600 7200 36000 72000 80000 86400
Sample Output 3
60 36000