-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmaller sum
More file actions
27 lines (23 loc) · 715 Bytes
/
Smaller sum
File metadata and controls
27 lines (23 loc) · 715 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def binary_search(arr, target):
left, right = 0, len(arr) - 1
while left <= right:
mid = (left + right) // 2
if arr[mid] < target:
left = mid + 1
else:
right = mid - 1
return left
def count_smaller_elements(first_array, second_array):
result = []
for num in second_array:
count = binary_search(first_array, num)
result.append(count)
return result
# Read input
n, m = map(int, input().split())
first_array = list(map(int, input().split()))
second_array = list(map(int, input().split()))
# Count smaller elements
output = count_smaller_elements(first_array, second_array)
# Print the result
print(' '.join(map(str, output)))