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

Envío 2829

Problema 0x25 - Suma de un subarreglo grande

  • Autor: sancanella
  • Fecha: 2021-02-07 01:46:01 UTC (Hace alrededor de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.134 s 16 KBi
#2
Correcto
0.147 s 15 KBi
#3
Correcto
0.141 s 15 KBi
#4
Correcto
0.149 s 16 KBi
#5
Correcto
0.132 s 15 KBi
#6
Correcto
0.217 s 12 KBi
#7
Correcto
0.162 s 16 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.753 s 125 KBi
#9
Tiempo límite excedido
1.066 s 85 KBi
#10
Tiempo límite excedido
1.099 s 74 KBi
#11
Tiempo límite excedido
1.124 s 84 KBi
#12
Tiempo límite excedido
1.036 s 84 KBi
#13
Tiempo límite excedido
1.154 s 85 KBi
#14
Tiempo límite excedido
1.064 s 86 KBi
Puntos totales: 50 / 100

Código

import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner teclado = new Scanner(System.in);
        teclado.nextLine();
        String[] entradas = teclado.nextLine().split(" ");
        int[] acc = new int[entradas.length];
        for (int i = 0; i < entradas.length; i++) {
            int n = Integer.parseInt(entradas[i]);
            if(i == 0){
                acc[i] = n;
            }else{
                acc[i] = n+acc[i-1];
            }
            
        }
        int checks = Integer.parseInt(teclado.nextLine());
        for (int i = 0; i < checks; i++) {
            String[] par  = teclado.nextLine().split(" ");
            int a = Integer.parseInt(par[0]);
            int b = Integer.parseInt(par[1]);
            int res = 0;
            if(a != 0){
                res = acc[a-1];
            }
            System.out.println(acc[b]-res);
        }
    }
}