Missing Number 1

Xem dạng PDF

Gửi bài giải

Điểm: 1,00 (OI)
Giới hạn thời gian: 1.0s
Giới hạn bộ nhớ: 256M
Input: stdin
Output: stdout

Nguồn bài:
Trịnh Thái Gia Bảo
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch

Bob loves solving number puzzles. After learning how to find the K-th smallest number in a sorted list, he now wants a bigger challenge.

This time, Bob wants to find the ~K-th~ smallest positive number that is not in his list.

The list contains distinct positive integers in increasing order. Some numbers are missing from the natural counting sequence, and Bob wants to find the one that comes ~K-th~ among those missing numbers.

Your task is to help Bob find the ~K-th~ missing number from a sorted list.


Input

  • The first line contains a single integer ~N (1 ≤ N ≤ 10^5)~ — the number of distinct integers in the list.
  • The second line contains ~N~ distinct positive integers: ~a_1, a_2, ..., a_n~ ~(1 ≤ a_1 < a_2 < ... < a_n ≤ 10^6)~, sorted in ascending order.
  • The third line contains a single integer ~K (1 ≤ K ≤ 10^6)~ — the K-th missing number to find.

Output

  • Print the ~K-th~ missing number.

📌 Example

Input
4  
3 5 6 7  
3
Output
4

💡 Explanation

The list is A = [3, 5, 6, 7].

The missing positive numbers are:
1, 2, 4, 8, 9, ...

The 3nd missing number is 4, so the answer is 4.


Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.