Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.016 s | 3 KBi |
#2 |
Correcto
|
0.015 s | 3 KBi |
#3 |
Correcto
|
0.016 s | 3 KBi |
#4 |
Correcto
|
0.016 s | 3 KBi |
#5 |
Correcto
|
0.016 s | 3 KBi |
#6 |
Incorrecto
|
0.015 s | 3 KBi |
#7 |
Incorrecto
|
0.014 s | 3 KBi |
#8 |
Correcto
|
0.016 s | 3 KBi |
#9 |
Correcto
|
0.019 s | 3 KBi |
#10 |
Incorrecto
|
0.015 s | 3 KBi |
#11 |
Incorrecto
|
0.015 s | 3 KBi |
#12 |
Incorrecto
|
0.381 s | 9 KBi |
#13 |
Incorrecto
|
0.368 s | 6 KBi |
#14 |
Incorrecto
|
0.471 s | 14 KBi |
#15 |
Correcto
|
0.42 s | 14 KBi |
#16 |
Correcto
|
0.373 s | 14 KBi |
#17 |
Correcto
|
0.377 s | 14 KBi |
def binary_search(arr, low, high, x): if high > low: mid = (high + low) // 2 if arr[mid] > x: return binary_search(arr, low, mid - 1, x) else: return binary_search(arr, mid + 1, high, x) elif high == low: if arr[len(arr) - 1] > x: return high else: return len(arr) else: # Element is not present in the array return low #Function call n = int(input()) elementsArray = [int(item) for item in input().split()] c = int(input()) querysArray = [] for i in range(0, c): querysArray.append(int(input())) resultArray = [0] * c for i in range(0, c): resultArray[i] = binary_search(elementsArray, 0, len(elementsArray)-1, querysArray[i]) for i in resultArray: print(i)