Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.083 s | 16 KBi |
#2 |
Correcto
|
0.087 s | 16 KBi |
#3 |
Correcto
|
0.118 s | 18 KBi |
#4 |
Correcto
|
0.088 s | 16 KBi |
#5 |
Correcto
|
0.089 s | 16 KBi |
#6 |
Correcto
|
0.09 s | 16 KBi |
#7 |
Correcto
|
0.089 s | 16 KBi |
#8 |
Correcto
|
0.082 s | 16 KBi |
#9 |
Correcto
|
0.087 s | 16 KBi |
#10 |
Correcto
|
0.085 s | 16 KBi |
#11 |
Correcto
|
0.165 s | 54 KBi |
#12 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.797 s | 125 KBi |
#13 |
Correcto
|
0.799 s | 118 KBi |
#14 |
Tiempo límite excedido
|
1.109 s | 78 KBi |
#15 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.905 s | 125 KBi |
#16 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.851 s | 125 KBi |
#17 |
Tiempo límite excedido
|
1.036 s | 86 KBi |
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int[] array = new int[n]; for(int i=0; i<n; i++){ array[i] = scanner.nextInt(); } int c = scanner.nextInt(); for(int i=0; i<c; i++){ System.out.println(succesorBinarySearch(0, n-1, array, scanner.nextInt())); } } private static int succesorBinarySearch(int start, int end, int[] array, int search){ if(start == end || end-start == 1){ if(search<array[start]){ return start; } if(search<array[end]){ return end; } return array.length; } int middle = (start+end)/2; if(array[middle-1]<=search && array[middle]>search){ return middle; } else if (search >= array[middle]){ return succesorBinarySearch(middle+1, end, array, search); } else { return succesorBinarySearch(start, middle-1, array, search); } } }