#BS0000002. Vị trí chèn (Search Insert Position)
Vị trí chèn (Search Insert Position)
Search Insert Position
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given distinct integers sorted increasingly and target, print its index if present. Otherwise print the index where it must be inserted so the array remains sorted. Equivalently, find the first with ; if none exists, answer . Required time: .
Input
The first line contains and target. The second line contains distinct increasing integers.
Output
Print the position of target or its insertion position.
Subtasks
- Subtask 1 — 20%:
targetlies outside . - Subtask 2 — 30%: .
- Subtask 3 — 50%: , .
Examples
Input
4 2
1 3 5 6
Output
1
Explanation
Inserting 2 at index produces .