Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.003 s | 1 KBi |
#2 |
Correcto
|
0.003 s | 1 KBi |
#3 |
Correcto
|
0.003 s | 1 KBi |
#4 |
Correcto
|
0.004 s | 29 KBi |
#5 |
Correcto
|
0.004 s | 27 KBi |
#6 |
Correcto
|
0.003 s | 1 KBi |
#7 |
Correcto
|
0.002 s | 1 KBi |
#8 |
Correcto
|
0.008 s | 3 KBi |
#9 |
Correcto
|
0.03 s | 1 KBi |
#10 |
Correcto
|
0.022 s | 1 KBi |
#11 |
Correcto
|
0.037 s | 2 KBi |
#12 |
Correcto
|
0.025 s | 2 KBi |
#13 |
Correcto
|
0.034 s | 2 KBi |
#14 |
Correcto
|
0.027 s | 2 KBi |
/* Code by Eduardo Vega */ #include <stdio.h> #include <stdlib.h> int main () { long int size = 0, num_consultas = 0, consulta1 = 0, consulta2 = 0, num = 0, suma = 0, i, j; long int *array = NULL; /* Get size and dynamically allocate array */ scanf("%li", &size); array = malloc(sizeof(long int) * size); /* Fill the array with the sum of last two input numbers */ /* This is more efficient than building the array with the original numbers, because this way we know the total sum at a given index without the need of looping */ for (i = 0; i < size; i++) { scanf("%li", &num); if (i == 0) array[i] = num; else array[i] = num + array[i - 1]; } /* Get the number of queries */ scanf("%li", &num_consultas); /* Iterate over and get queries */ for (i = 0; i < num_consultas; i++) { scanf("%li %li", &consulta1, &consulta2); if (consulta1 == 0) suma = array[consulta2]; else suma = array[consulta2] - array[consulta1 - 1]; printf("%li\n", suma); suma = 0; } free(array); return 0; }