#BS0000176. Số nguyên dương bị thiếu thứ K (Kth Missing Positive Number)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Số nguyên dương bị thiếu thứ K (Kth Missing Positive Number)
Kth Missing Positive Number
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
You are given distinct positive integers in strictly increasing order. A positive integer is missing if it does not occur in the array.
Consider all missing positive integers in increasing order. Find the value of the -th missing positive integer, using one-based counting.
For example, if the array is , the missing integers begin with .
Input
- The first line contains integers and : the array size and the missing-number rank.
- The second line contains exactly integers in strictly increasing order.
Output
Print one integer: the value of the -th missing positive integer.
Subtasks
-
Subtask 1 (20 points): ; ; .
-
Subtask 2 (30 points): ; ; .
-
Subtask 3 (50 points): ; ; .
Examples
Example 1
Input
5 5
2 3 4 7 11
Output
9
Explanation
The array contains . Its missing positive integers are . In order, the first five are , , , , and . Thus, for , the output is 9.
Example 2
Input
4 2
1 2 3 4
Output
6
Explanation
The first four positive integers are present, so the missing values start at . The second missing value is 6.