Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.137 s | 13 KBi |
#2 |
Correcto
|
0.124 s | 13 KBi |
#3 |
Correcto
|
0.129 s | 13 KBi |
#4 |
Correcto
|
0.135 s | 13 KBi |
#5 |
Correcto
|
0.129 s | 13 KBi |
#6 |
Correcto
|
0.149 s | 14 KBi |
#7 |
Correcto
|
0.137 s | 13 KBi |
#8 |
Correcto
|
0.682 s | 34 KBi |
#9 |
Tiempo límite excedido
|
1.024 s | 79 KBi |
#10 |
Tiempo límite excedido
|
1.021 s | 98 KBi |
#11 |
Tiempo límite excedido
|
1.052 s | 99 KBi |
#12 |
Tiempo límite excedido
|
1.044 s | 88 KBi |
#13 |
Tiempo límite excedido
|
1.073 s | 99 KBi |
#14 |
Tiempo límite excedido
|
1.012 s | 84 KBi |
import java.util.Scanner; public class Main { public void solve(int[] a, int[] s, int p, int q) { int sum = s[q]; /*int[] s = new int[a.length]; for (int i = p; i <= q; i++) { sum += a[i]; s[i] = sum; }*/ if (p-1 >= 0) { sum -= s[p - 1]; } System.out.println(sum); } public static void main(String[] args) { Main solve = new Main(); Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int [] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } int[] s = new int[n]; int sum = 0; for (int i = 0; i < n; i++) { sum += a[i]; s[i] = sum; } int c = sc.nextInt(); int p = 0; int q = 0; for (int k = 0; k < c; k++) { p = sc.nextInt(); q = sc.nextInt(); solve.solve(a, s, p, q); } } }