#K34427. Find the K-th Missing Positive Integer

    ID: 25307 Type: Default 1000ms 256MiB

Find the K-th Missing Positive Integer

Find the K-th Missing Positive Integer

You are given a sorted array arr of positive integers and an integer k. Your task is to find the k-th missing positive integer that is not present in arr.

More formally, if we denote by \(M\) the set of missing positive integers (i.e. numbers that are not in \(arr\)), then you should output the element at position k in the sorted order of \(M\). For example, if arr = [2,3,4,7,11] and \(k=5\), the missing numbers are [1,5,6,8,9,10,...] so the answer is 9.

You can assume that \(arr\) is strictly increasing.

inputFormat

The input is given from stdin in the following format:

  • The first line contains an integer n, representing the number of elements in the array arr.
  • If n > 0, the second line contains n space-separated positive integers, representing the sorted array arr.
  • The last line contains the integer k.

outputFormat

Output a single integer to stdout representing the k-th missing positive integer.

## sample
5
2 3 4 7 11
5
9