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

Envío 2853

Problema 0x25 - Suma de un subarreglo grande

  • Autor: pradomaricon
  • Fecha: 2021-02-07 04:40:06 UTC (Hace alrededor de 3 años)
Caso # Resultado Tiempo Memoria
#1
Incorrecto
0.154 s 15 KBi
#2
Incorrecto
0.155 s 15 KBi
#3
Correcto
0.161 s 15 KBi
#4
Correcto
0.186 s 12 KBi
#5
Incorrecto
0.174 s 12 KBi
#6
Incorrecto
0.175 s 16 KBi
#7
Incorrecto
0.174 s 16 KBi
#8
Tiempo límite excedido
1.062 s 105 KBi
#9
Tiempo límite excedido
1.145 s 86 KBi
#10
Tiempo límite excedido
1.111 s 85 KBi
#11
Tiempo límite excedido
1.055 s 42 KBi
#12
Tiempo límite excedido
1.041 s 85 KBi
#13
Tiempo límite excedido
1.045 s 85 KBi
#14
Tiempo límite excedido
1.087 s 84 KBi
Puntos totales: 15 / 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;
}
    }