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

Envío 2854

Problema 0x25 - Suma de un subarreglo grande

  • Autor: pradomaricon
  • Fecha: 2021-02-07 04:40:31 UTC (Hace alrededor de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.131 s 16 KBi
#2
Correcto
0.15 s 16 KBi
#3
Correcto
0.144 s 16 KBi
#4
Correcto
0.139 s 15 KBi
#5
Correcto
0.144 s 16 KBi
#6
Correcto
0.167 s 16 KBi
#7
Correcto
0.152 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.745 s 125 KBi
#9
Tiempo límite excedido
1.129 s 85 KBi
#10
Tiempo límite excedido
1.064 s 39 KBi
#11
Tiempo límite excedido
1.048 s 84 KBi
#12
Tiempo límite excedido
1.046 s 85 KBi
#13
Tiempo límite excedido
1.068 s 43 KBi
#14
Tiempo límite excedido
1.152 s 84 KBi
Puntos totales: 50 / 100

Código

import java.util.Scanner;

public class Main {
    
    public static Scanner leer = new Scanner(System.in);
    public static void main(String[] args) {

        //input dimensiones
        String dimensiones = leer.nextLine().trim();
        int filas = Integer.parseInt(dimensiones);
       
        int[] ejemplo1 = new int[filas];
        
        //input de datos
        
            String[] filaDada = leer.nextLine().trim().split(" ");
            int k = 0;
            for (int j = 0; j < filas; j++) {
                ejemplo1[j] = Integer.parseInt(filaDada[k]);
                k++;
                //System.out.println(ejemplo1[i][j]);
            }
            
        //
        String numc = leer.nextLine().trim();
        int numConsultas=Integer.parseInt(numc);
        
        for (int i = 0; i < numConsultas; i++) {
            String[] cons = leer.nextLine().trim().split(" ");
            int comienzo=Integer.parseInt(cons[0]);
            int finaliza=Integer.parseInt(cons[1]);
            
            System.out.println(sumaSubarreglo(ejemplo1,filas,comienzo, finaliza));
            
        }
 
    }
    
    
    
    public static int cantidadMayores(int[] matriz, int filas, int consulta) {
     
        int toret=0;
        
        for (int i = 0; i < filas; i++) {
            if (matriz[i]>consulta){
                toret++;
            }
            
        }
        return toret;
        
    }
    
    public static int sumaSubarreglo(int[] matriz, int filas, int comienzo, int finaliza){
        int toret=0;
        
        for (int i = comienzo; i <= finaliza; i++) {
            toret+=matriz[i]; 
        }
        return toret;
}
    }