Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.004 s | 2 KBi |
#2 |
Correcto
|
0.002 s | 0 KBi |
#3 |
Correcto
|
0.002 s | 0 KBi |
#4 |
Correcto
|
0.001 s | 0 KBi |
#5 |
Correcto
|
0.002 s | 0 KBi |
#6 |
Correcto
|
0.002 s | 2 KBi |
#7 |
Correcto
|
0.002 s | 0 KBi |
#8 |
Correcto
|
0.002 s | 0 KBi |
#9 |
Correcto
|
0.005 s | 11 KBi |
#10 |
Correcto
|
0.002 s | 0 KBi |
#11 |
Correcto
|
0.009 s | 2 KBi |
#12 |
Correcto
|
0.014 s | 1 KBi |
#13 |
Correcto
|
0.025 s | 2 KBi |
#14 |
Correcto
|
0.025 s | 1 KBi |
#15 |
Correcto
|
0.038 s | 2 KBi |
#16 |
Correcto
|
0.028 s | 2 KBi |
#17 |
Correcto
|
0.019 s | 1 KBi |
#include <bits/stdc++.h> using namespace std; int binarySearch(int *arr, int X, int r, int l){ if(r < l && l > 0){ int m = l + (r - l) / 2; if(arr[m-1] <= X){ if(arr[m] > X){ return m; }else{ return binarySearch(arr, X, m, l); } }else{ return binarySearch(arr, X, r, m-1); } } return arr[l] > X ? l : -1; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // your code goes here int N, C, X, i; cin >> N; int arr[N]; for(i=0; i<N; i++) cin >> arr[i]; cin >> C; while(C--){ cin >> X; i = binarySearch(arr, X, 0, N-1); cout << (i >= 0 ? i : N) << "\n"; } return 0; }