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

Envío 4241

Problema 0x25 - Suma de un subarreglo grande

  • Autor: andres0608
  • Fecha: 2021-05-30 03:01:26 UTC (Hace casi 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.122 s 13 KBi
#2
Correcto
0.139 s 14 KBi
#3
Correcto
0.166 s 12 KBi
#4
Correcto
0.14 s 14 KBi
#5
Correcto
0.133 s 14 KBi
#6
Correcto
0.164 s 18 KBi
#7
Correcto
0.239 s 15 KBi
#8
Tiempo límite excedido
1.028 s 40 KBi
#9
Tiempo límite excedido
1.044 s 53 KBi
#10
Tiempo límite excedido
1.016 s 52 KBi
#11
Tiempo límite excedido
1.121 s 53 KBi
#12
Tiempo límite excedido
1.056 s 54 KBi
#13
Tiempo límite excedido
1.057 s 53 KBi
#14
Tiempo límite excedido
1.104 s 54 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 = suma + Integer.parseInt(v[i]);
		 }
		 return suma;
	 }
}