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

Envío 1220

Problema 0x25 - Suma de un subarreglo grande

  • Autor: datruq
  • Fecha: 2020-10-12 03:53:07 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.181 s 13 KBi
#2
Correcto
0.189 s 13 KBi
#3
Correcto
0.166 s 13 KBi
#4
Correcto
0.17 s 13 KBi
#5
Correcto
0.129 s 19 KBi
#6
Correcto
0.215 s 14 KBi
#7
Correcto
0.146 s 15 KBi
#8
Tiempo límite excedido
1.049 s 90 KBi
#9
Tiempo límite excedido
1.152 s 55 KBi
#10
Tiempo límite excedido
1.115 s 54 KBi
#11
Tiempo límite excedido
1.039 s 74 KBi
#12
Tiempo límite excedido
1.089 s 54 KBi
#13
Tiempo límite excedido
1.051 s 37 KBi
#14
Tiempo límite excedido
1.083 s 55 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;
        }
        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);
        }
    }
}