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

Envío 3329

Problema 0x25 - Suma de un subarreglo grande

  • Autor: datruq
  • Fecha: 2021-03-10 04:23:27 UTC (Hace alrededor de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.139 s 15 KBi
#2
Correcto
0.132 s 16 KBi
#3
Correcto
0.141 s 16 KBi
#4
Correcto
0.135 s 16 KBi
#5
Correcto
0.198 s 53 KBi
#6
Correcto
0.167 s 16 KBi
#7
Correcto
0.154 s 15 KBi
#8
Error en tiempo de ejecución (NZEC)
Exited with error status 137
run: line 1:     3 Killed                  /usr/local/openjdk13/bin/java Main
0.714 s 125 KBi
#9
Esperando resultado...
#10
Esperando resultado...
#11
Tiempo límite excedido
1.175 s 85 KBi
#12
Tiempo límite excedido
1.148 s 85 KBi
#13
Tiempo límite excedido
1.051 s 85 KBi
#14
Esperando resultado...
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;
        }
        Integer[] sum = new Integer[size];
        int suma = 0;
        for (int j = 0; j < size; j++) {
            suma += entries[j];
            sum[j] = suma;
        }
        for (int i = 0; i < subArrSize; i++) {
            String[] subItems = sn.nextLine().split(" ");
            int p = Integer.parseInt(subItems[0]);
            int q = Integer.parseInt(subItems[1]);
            int res = sum[q] - sum[p] + entries[p];
            System.out.println(res);
        }
    }

}