forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1.py
20 lines (16 loc) Β· 723 Bytes
/
1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from bisect import bisect_left, bisect_right
# κ°μ΄ [left_value, right_value]μΈ λ°μ΄ν°μ κ°μλ₯Ό λ°ννλ ν¨μ
def count_by_range(array, left_value, right_value):
right_index = bisect_right(array, right_value)
left_index = bisect_left(array, left_value)
return right_index - left_index
n, x = map(int, input().split()) # λ°μ΄ν°μ κ°μ N, μ°Ύκ³ μ νλ κ° x μ
λ ₯ λ°κΈ°
array = list(map(int, input().split())) # μ 체 λ°μ΄ν° μ
λ ₯ λ°κΈ°
# κ°μ΄ [x, x] λ²μμ μλ λ°μ΄ν°μ κ°μ κ³μ°
count = count_by_range(array, x, x)
# κ°μ΄ xμΈ μμκ° μ‘΄μ¬νμ§ μλλ€λ©΄
if count == 0:
print(-1)
# κ°μ΄ xμΈ μμκ° μ‘΄μ¬νλ€λ©΄
else:
print(count)