Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.085 s | 16 KBi |
#2 |
Correcto
|
0.087 s | 16 KBi |
#3 |
Correcto
|
0.114 s | 18 KBi |
#4 |
Correcto
|
0.087 s | 16 KBi |
#5 |
Correcto
|
0.086 s | 16 KBi |
#6 |
Correcto
|
0.111 s | 17 KBi |
#7 |
Correcto
|
0.103 s | 17 KBi |
#8 |
Correcto
|
0.539 s | 57 KBi |
#9 |
Tiempo límite excedido
|
1.083 s | 124 KBi |
#10 |
Correcto
|
0.82 s | 125 KBi |
#11 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.751 s | 125 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.709 s | 125 KBi |
#13 |
Correcto
|
0.803 s | 125 KBi |
#14 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.982 s | 125 KBi |
import java.util.HashMap; import java.util.Objects; 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]; HashMap<Integer, Integer> sums = new HashMap<>(); int key1 = 0; int total = 0; for(int i=0; i<n; i++){ array[i]=scanner.nextInt(); total += array[i]; sums.put(Objects.hash(key1, i), total); } total = 0; int key2 = n-1; for(int i=n-1; i>=0; i--){ total+=array[i]; key1 = i; sums.put(Objects.hash(key1, key2), total); } int c = scanner.nextInt(); for(int i=0; i<c; i++){ int left = scanner.nextInt(); int right = scanner.nextInt(); total = sums.get(Objects.hash(0, n-1)); int sumLeft = left!= 0 ? sums.get(Objects.hash(0, left-1)) : 0; int sumRight = right != n-1 ? sums.get(Objects.hash(right+1, n-1)) : 0; System.out.println(total - sumLeft - sumRight); } } }