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

Envío 2835

Problema 0x25 - Suma de un subarreglo grande

  • Autor: sancanella
  • Fecha: 2021-02-07 02:10:19 UTC (Hace alrededor de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.228 s 23 KBi
#2
Correcto
0.175 s 16 KBi
#3
Correcto
0.184 s 16 KBi
#4
Correcto
0.227 s 25 KBi
#5
Correcto
0.177 s 16 KBi
#6
Correcto
0.191 s 16 KBi
#7
Correcto
0.234 s 30 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.711 s 125 KBi
#9
Tiempo límite excedido
1.006 s 84 KBi
#10
Tiempo límite excedido
1.03 s 85 KBi
#11
Tiempo límite excedido
1.056 s 85 KBi
#12
Tiempo límite excedido
1.036 s 43 KBi
#13
Tiempo límite excedido
1.095 s 125 KBi
#14
Tiempo límite excedido
1.054 s 84 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());
        StringBuilder sb = new StringBuilder();
        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];
            }
            sb.append((acc[b]-res)+"\n");
        }
         System.out.println(sb.toString());
    }
}