1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
n, m = map(int, input().split())
ar = list(map(int, input().split()))
def binary_search(ar, num):
first, last = 0, len(ar)-1
while first<=last:
mid = (first+last)//2
if ar[mid] == num:
return mid+1
elif ar[mid] < num:
first=mid+1
else:
last=mid-1
ar.sort()
num_idx=binary_search(ar, m)
print(num_idx)
|
cs |
728x90
'Data Structures & Algorithms' 카테고리의 다른 글
[Algorithms] 결정&그리디 알고리즘-뮤직비디오(결정 알고리즘) (0) | 2022.05.15 |
---|---|
[Algorithms] 결정&그리디 알고리즘-랜선 자르기(결정 알고리즘) (0) | 2022.05.15 |
[Algorithms] Basic-격자판 회문수 (0) | 2022.05.15 |
[Algorithms] Basic-스도쿠 검사 (0) | 2022.05.14 |
[Algorithms] Basic-봉우리 (0) | 2022.05.14 |