Problems > The K-th Missing Number

The K-th Missing Number

Difficulty: 1500 3000 ms 128 MB

binary-search

A strictly increasing array of positive integers is given. Print the K-th positive integer that does NOT appear in it.

Input: the first line has N and K; the second line has the N sorted values.

Output: the K-th missing positive integer.

Constraints:

  • 1 ≤ N ≤ 105
  • 1 ≤ K ≤ 105
  • 1 ≤ ai ≤ 2×105, strictly increasing

Sample Tests

Input 1
4 2
2 3 4 7
Output 1
5
Input 2
2 4
1 2
Output 2
6

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.