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

Envío 1094

Problema 0x25 - Suma de un subarreglo grande

  • Autor: datruq
  • Fecha: 2020-10-10 03:11:26 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.151 s 12 KBi
#2
Correcto
0.151 s 12 KBi
#3
Correcto
0.16 s 17 KBi
#4
Correcto
0.149 s 13 KBi
#5
Correcto
0.158 s 25 KBi
#6
Correcto
0.184 s 12 KBi
#7
Correcto
0.153 s 53 KBi
#8
Tiempo límite excedido
0.39 s 26 KBi
#9
Tiempo límite excedido
0.562 s 39 KBi
#10
Tiempo límite excedido
0.527 s 38 KBi
#11
Tiempo límite excedido
0.565 s 39 KBi
#12
Tiempo límite excedido
0.491 s 39 KBi
#13
Tiempo límite excedido
0.599 s 39 KBi
#14
Tiempo límite excedido
0.558 s 46 KBi
Puntos totales: 50 / 100

Código

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sn = new Scanner(System.in);
        int size = Integer.parseInt(sn.nextLine());
        String[] arItems = sn.nextLine().split(" ");
        int subArrSize = Integer.parseInt(sn.nextLine());
        Integer[] entries = new Integer[size];
        for (int i = 0; i < size; i++) {
            int arItem = Integer.parseInt(arItems[i]);
            entries[i] = arItem;
        }
        for (int i = 0; i < subArrSize; i++) {
            String[] subItems = sn.nextLine().split(" ");
            int suma = sumaSubArreglo(entries, Integer.parseInt(subItems[0]), Integer.parseInt(subItems[1]));
            System.out.println(suma);
        }
    }

    private static int sumaSubArreglo(Integer[] entries, int p, int q) {
        int sum = 0;
        for (int i = p; i <= q; i++) {
            sum += entries[i];
        }
        return sum;
    }

}