█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 4338

Problema 0x25 - Suma de un subarreglo grande

  • Autor: saris123
  • Fecha: 2021-06-10 01:13:27 UTC (Hace casi 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.176 s 14 KBi
#2
Correcto
0.127 s 12 KBi
#3
Correcto
0.163 s 14 KBi
#4
Correcto
0.183 s 16 KBi
#5
Correcto
0.125 s 38 KBi
#6
Correcto
0.158 s 27 KBi
#7
Correcto
0.205 s 30 KBi
#8
Correcto
0.698 s 36 KBi
#9
Tiempo límite excedido
1.01 s 95 KBi
#10
Tiempo límite excedido
1.135 s 98 KBi
#11
Tiempo límite excedido
1.166 s 125 KBi
#12
Tiempo límite excedido
1.117 s 94 KBi
#13
Tiempo límite excedido
1.143 s 94 KBi
#14
Tiempo límite excedido
1.119 s 95 KBi
Puntos totales: 58 / 100

Código

import java.util.*;

public class Main {
    public static void main(String[] args){
    	Scanner sc= new Scanner(System.in);
        int N = sc.nextInt();
        int numberArray[] = new int[N];
        for(int i = 0; i < N; i++)
        {
            numberArray[i] = sc.nextInt();
        }
        
        int C = sc.nextInt();
        int pArray[] = new int[C];
        int qArray[] = new int[C];
        for(int i = 0; i < C; i++)
        {
            pArray[i] = sc.nextInt();
            qArray[i] = sc.nextInt();
        }
        sc.close();

        for(int i = 0; i < C; i++)
        {
            System.out.println(SumArray(numberArray, pArray[i], qArray[i]));
        }
    }

     private static int SumArray(int[] array, int startIndex, int endIndex) {
    	int result = 0;
        for (int i = startIndex; i <= endIndex; i++) {
            result = result + array[i] ;
        }
        return result;
    }
}