Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.016 s | 3 KBi |
#2 |
Incorrecto
|
0.015 s | 3 KBi |
#3 |
Incorrecto
|
0.016 s | 3 KBi |
#4 |
Incorrecto
|
0.015 s | 3 KBi |
#5 |
Incorrecto
|
0.015 s | 3 KBi |
#6 |
Incorrecto
|
0.016 s | 3 KBi |
#7 |
Incorrecto
|
0.014 s | 3 KBi |
#8 |
Incorrecto
|
0.017 s | 3 KBi |
#9 |
Incorrecto
|
0.017 s | 3 KBi |
#10 |
Incorrecto
|
0.016 s | 3 KBi |
#11 |
Incorrecto
|
0.016 s | 3 KBi |
#12 |
Incorrecto
|
0.418 s | 9 KBi |
#13 |
Incorrecto
|
0.381 s | 7 KBi |
#14 |
Incorrecto
|
0.457 s | 14 KBi |
#15 |
Correcto
|
0.387 s | 14 KBi |
#16 |
Correcto
|
0.367 s | 14 KBi |
#17 |
Correcto
|
0.369 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: # Element is not present in the array 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)