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

Envío 4974

Problema 0x25 - Suma de un subarreglo grande

  • Autor: martinarriaga
  • Fecha: 2021-10-02 22:27:30 UTC (Hace más de 2 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.154 s 12 KBi
#2
Correcto
0.162 s 12 KBi
#3
Correcto
0.311 s 12 KBi
#4
Correcto
0.331 s 12 KBi
#5
Correcto
0.287 s 12 KBi
#6
Correcto
0.411 s 13 KBi
#7
Correcto
0.168 s 22 KBi
#8
Tiempo límite excedido
1.277 s 38 KBi
#9
Tiempo límite excedido
1.173 s 90 KBi
#10
Tiempo límite excedido
1.119 s 94 KBi
#11
Tiempo límite excedido
1.024 s 93 KBi
#12
Tiempo límite excedido
1.081 s 91 KBi
#13
Tiempo límite excedido
1.186 s 26 KBi
#14
Tiempo límite excedido
1.082 s 93 KBi
Puntos totales: 50 / 100

Código

import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] numeros = new int[n];
        for (int i = 0; i < n; i++)
        {
             numeros[i] = scanner.nextInt();
        }
        int c = scanner.nextInt();
        int[] consultasp = new int[c];
        int[] consultasq = new int[c];
        for (int i = 0; i < c; i++)
        {
            consultasp[i] = scanner.nextInt();
            consultasq[i] = scanner.nextInt();
        }
        int acu;
        for (int i = 0; i < c; i++)
        {
            acu = 0;
            int consultaActualP = consultasp[i];
            int consultaActualQ = consultasq[i];
            for (; consultaActualP <= consultaActualQ; consultaActualP++)
            {
                acu += numeros[consultaActualP];
            }
            System.out.println(acu);
        } 
    }
}