#K3111. Earliest Completion Day
Earliest Completion Day
Earliest Completion Day
Alice is an avid reader. She has a schedule of days on which she is available to read books. Each day in the schedule is numbered in increasing order. She reads exactly one book on each available day. Given an integer d representing the total number of books she wants to read and a list of n sorted integers indicating the days she can read, determine the earliest day on which she can finish reading d books.
If the number of available days is less than d, then it is impossible for her to finish reading all d books, and you should output -1.
The solution can be formally described as follows: If the sorted array is \(a_1, a_2, \dots, a_n\), then the answer is \(a_d\) provided \(n \ge d\); otherwise, the output is \(-1\).
inputFormat
The input is read from standard input (stdin
) and has the following format:
- The first line contains two integers
n
andd
, wheren
is the number of available reading days andd
is the number of books to read. - The second line contains
n
space-separated integers representing the days (in increasing order) on which Alice can read.
outputFormat
Output the earliest day (from stdout
) by which Alice can finish reading d
books. If it is impossible because there are fewer than d
available days, output -1
.
7 5
1 3 5 7 8 10 12
8