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

Envío 4243

Problema 0x25 - Suma de un subarreglo grande

  • Autor: andres0608
  • Fecha: 2021-05-30 03:11:27 UTC (Hace casi 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.136 s 20 KBi
#2
Correcto
0.131 s 12 KBi
#3
Correcto
0.2 s 15 KBi
#4
Correcto
0.143 s 21 KBi
#5
Correcto
0.118 s 33 KBi
#6
Correcto
0.168 s 14 KBi
#7
Correcto
0.165 s 16 KBi
#8
Tiempo límite excedido
1.046 s 65 KBi
#9
Tiempo límite excedido
1.065 s 53 KBi
#10
Tiempo límite excedido
1.047 s 53 KBi
#11
Tiempo límite excedido
1.144 s 55 KBi
#12
Tiempo límite excedido
1.109 s 53 KBi
#13
Tiempo límite excedido
1.14 s 53 KBi
#14
Tiempo límite excedido
1.123 s 53 KBi
Puntos totales: 50 / 100

Código

import java.util.*;
public class Main {

     public static void main(String[] args) throws Exception {
		 
		 String  numero1, numero2,numero3,valor,numero4;
		 Scanner numeros = new Scanner(System.in);
		 numero1 = numeros.nextLine();
		 numero2="";
		 numero2 += numeros.nextLine();
		 numero3= numeros.nextLine();
		 String[] numbers = numero2.split(" ");
		 int result;
		 for(int i=0;i < Integer.parseInt(numero3);i++) {
			 numero4="";
			 numero4+= numeros.nextLine();
			 result = contar(numbers, numero4);
			 System.out.println(result);
		 }
		 numeros.close();  
		 
	 }
	 
	 
	 public static int contar(String[] v, String c) {
		 String[] valores = c.split(" ");
		 int suma=0;
		 for(int i= Integer.parseInt(valores[0]); i <= Integer.parseInt(valores[1]); i++) {
			 suma += Integer.parseInt(v[i]);
		 }
		 return suma;
	 }
}