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

Envío 3787

Problema 0x25 - Suma de un subarreglo grande

  • Autor: asadoenolla
  • Fecha: 2021-04-16 04:22:20 UTC (Hace alrededor de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.117 s 16 KBi
#2
Correcto
0.12 s 16 KBi
#3
Correcto
0.105 s 16 KBi
#4
Correcto
0.135 s 27 KBi
#5
Correcto
0.128 s 24 KBi
#6
Correcto
0.144 s 17 KBi
#7
Correcto
0.151 s 17 KBi
#8
Correcto
0.826 s 54 KBi
#9
Tiempo límite excedido
1.2 s 62 KBi
#10
Tiempo límite excedido
1.159 s 50 KBi
#11
Tiempo límite excedido
1.029 s 66 KBi
#12
Tiempo límite excedido
1.039 s 59 KBi
#13
Tiempo límite excedido
1.086 s 92 KBi
#14
Tiempo límite excedido
1.06 s 57 KBi
Puntos totales: 58 / 100

Código

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int arr[] = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		int c = sc.nextInt();

		for (int i = 0; i < c; i++) {
			int j = sc.nextInt();
			int k = sc.nextInt();
			System.out.println(Sum(j, k, arr));
		}
		sc.close();

	}

	public static int Sum(int j, int k, int[] arr) {
		int total = 0;
		for (int i = j; i <= k; i++) {
			total = total + arr[i];
		}
		return total;
	}

}