Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.099 s | 17 KBi |
#2 |
Correcto
|
0.085 s | 16 KBi |
#3 |
Correcto
|
0.086 s | 16 KBi |
#4 |
Correcto
|
0.085 s | 16 KBi |
#5 |
Correcto
|
0.084 s | 16 KBi |
#6 |
Correcto
|
0.074 s | 16 KBi |
#7 |
Correcto
|
0.106 s | 17 KBi |
#8 |
Correcto
|
0.157 s | 13 KBi |
#9 |
Correcto
|
0.077 s | 16 KBi |
#10 |
Correcto
|
0.084 s | 16 KBi |
#11 |
Correcto
|
0.082 s | 16 KBi |
#12 |
Correcto
|
0.773 s | 118 KBi |
#13 |
Correcto
|
0.73 s | 119 KBi |
#14 |
Tiempo límite excedido
|
1.178 s | 79 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.893 s | 125 KBi |
#16 |
Correcto
|
0.751 s | 122 KBi |
#17 |
Correcto
|
0.736 s | 124 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); } } }