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

Envío 4341

Problema 0x25 - Suma de un subarreglo grande

  • Autor: saris123
  • Fecha: 2021-06-10 02:15:20 UTC (Hace casi 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.169 s 18 KBi
#2
Correcto
0.158 s 38 KBi
#3
Correcto
0.132 s 14 KBi
#4
Correcto
0.151 s 12 KBi
#5
Correcto
0.153 s 12 KBi
#6
Correcto
0.155 s 25 KBi
#7
Correcto
0.151 s 31 KBi
#8
Correcto
0.679 s 74 KBi
#9
Tiempo límite excedido
1.126 s 53 KBi
#10
Tiempo límite excedido
1.012 s 53 KBi
#11
Tiempo límite excedido
1.056 s 53 KBi
#12
Tiempo límite excedido
1.028 s 55 KBi
#13
Tiempo límite excedido
1.07 s 94 KBi
#14
Tiempo límite excedido
1.078 s 88 KBi
Puntos totales: 58 / 100

Código

import java.util.Arrays;
import java.util.Scanner;

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 resultArray[] = new int[C];
        for(int i = 0; i < C; i++)
        {
        	resultArray[i] = SumArray(numberArray, sc.nextInt(), sc.nextInt());
        }
        sc.close();
        
        Arrays.stream(resultArray).forEach(System.out::println);
    }

     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;
    }
}