Professional Documents
Culture Documents
Problem - 1650E - Codeforces
Problem - 1650E - Codeforces
|
stdfloat | Logout
HOME TOP CATALOG CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP
Now Dmitry has a session, and he has to pass n exams. The session starts on day 1 and → Virtual participation
lasts d days. The i th exam will take place on the day of ai (1 ≤ ai ≤ d ), all ai — are
different.
→ Clone Contest to Mashup
→ Submit?
Sample, where n , ,
= 3 d = 12 a = [3, 5, 9] . Orange — exam days. Before the first exam Dmitry will rest 2
Language: GNU G++20 11.2.0 (64 bit, w
days, before the second he will rest 1 day and before the third he will rest 3 days.
For the session schedule, Dmitry considers a special value μ — the smallest of the rest times Choose
Choose File No file chosen
before the exam for all exams. For example, for the image above, μ = 1 . In other words, for file:
the schedule, he counts exactly n numbers — how many days he rests between the exam
Submit
i − 1 and i (for i = 0 between the start of the session and the exam i ). Then it finds μ — the
Dmitry believes that he can improve the schedule of the session. He may ask to change the → Contest materials
date of one exam (change one arbitrary value of ai ). Help him change the date so that all ai
remain different, and the value of μ is as large as possible. Announcement
Tutorial (en)
For example, for the schedule above, it is most advantageous for Dmitry to move the second
exam to the very end of the session. The new schedule will take the form:
Now the rest periods before exams are equal to [2, 2, 5]. So, μ = 2 .
Dmitry can leave the proposed schedule unchanged (if there is no way to move one exam so
that it will lead to an improvement in the situation).
Input
The first line of input data contains an integer t (1
4
≤ t ≤ 10 ) — the number of input test
cases. The descriptions of test cases follow.
The first line of each test case contains two integers n and d (
5
2 ≤ n ≤ 2 ⋅ 10 , 1 ≤ d ≤ 10
9
) — the number of exams and the length of the session,
respectively.
The second line of each test case contains n integers ai (1 ≤ ai ≤ d, ai < ai+1 ), where the
i -th number means the date of the i -th exam.
5
It is guaranteed that the sum of n for all test cases does not exceed 2 ⋅ 10 .
Output
For each test case, output the maximum possible value of μ if Dmitry can move any one exam
to an arbitrary day. All values of ai should remain distinct.
Example
https://codeforces.com/problemset/problem/1650/E 1/3
2/20/24, 9:35 PM Problem - 1650E - Codeforces
input Copy
3 12
3 5 9
2 5
1 5
2 100
1 2
5 15
3 6 9 12 15
3 1000000000
1 400000000 500000000
2 10
3 4
2 2
1 2
4 15
6 11 12 13
2 20
17 20
output Copy
2
1
1
2
99999999
3
0
1
9
Note
The first sample is parsed in statement.
Initial schedule.
New schedule.
In the third sample, we need to move the exam from day 1 to any day from 4 to 100.
In the fourth sample, any change in the schedule will only reduce μ, so the schedule should be
left as it is.
In the fifth sample, we need to move the exam from day 1 to any day from 100000000 to
300000000 .
https://codeforces.com/problemset/problem/1650/E 2/3
2/20/24, 9:35 PM Problem - 1650E - Codeforces
Initial schedule.
New schedule.
In the seventh sample, every day is exam day, and it is impossible to rearrange the schedule.
Supported by
https://codeforces.com/problemset/problem/1650/E 3/3