#BS0000001. Tìm kiếm nhị phân (Binary Search)
Tìm kiếm nhị phân (Binary Search)
Binary Search
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given distinct integers sorted increasingly and an integer target, find its index. Print -1 if it is absent. Indices start at . The required time complexity is .
Input
The first line contains and target. The second line contains strictly increasing integers.
Output
Print the index of target, or -1 if it is absent.
Subtasks
- Subtask 1 — 20%: .
- Subtask 2 — 30%: .
- Subtask 3 — 50%: , .
Examples
Input
6 9
-1 0 3 5 9 12
Output
4
Explanation
9 is stored at , so the answer is .