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

Envío 3016

Problema 0x25 - Suma de un subarreglo grande

  • Autor: davidtoca
  • Fecha: 2021-02-15 02:11:36 UTC (Hace alrededor de 3 años)
Caso # Resultado Tiempo Memoria
#1
Incorrecto
0.151 s 15 KBi
#2
Correcto
0.169 s 15 KBi
#3
Correcto
0.144 s 15 KBi
#4
Correcto
0.159 s 16 KBi
#5
Correcto
0.149 s 16 KBi
#6
Incorrecto
0.207 s 13 KBi
#7
Incorrecto
0.204 s 16 KBi
#8
Incorrecto
0.848 s 52 KBi
#9
Tiempo límite excedido
1.1 s 63 KBi
#10
Tiempo límite excedido
1.118 s 72 KBi
#11
Tiempo límite excedido
1.14 s 70 KBi
#12
Tiempo límite excedido
1.121 s 68 KBi
#13
Tiempo límite excedido
1.026 s 67 KBi
#14
Tiempo límite excedido
1.02 s 56 KBi
Puntos totales: 29 / 100

Código

import java.util.Scanner;

class Main {

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

        int n = sc.nextInt();

        int[] array = new int[n];
        int total = 0;
        for(int i=0; i<n;i++){
            array[i] = sc.nextInt();
            total+=array[i];
            array[i]=total;
        }

        int cases = sc.nextInt();

        for(int i=0; i<cases;i++){
            int p = sc.nextInt();
            int q = sc.nextInt();

            if(p == 0){
                System.out.println(array[p]);
            } else {
                System.out.println(array[q]- array[p-1]);
            }
        }

    }
}