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

Envío 1738

Problema 0x25 - Suma de un subarreglo grande

  • Autor: JulianMi12
  • Fecha: 2020-11-06 19:29:37 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.1 s 12 KBi
#2
Correcto
0.09 s 13 KBi
#3
Correcto
0.08 s 12 KBi
#4
Correcto
0.094 s 12 KBi
#5
Correcto
0.1 s 12 KBi
#6
Correcto
0.103 s 12 KBi
#7
Correcto
0.105 s 12 KBi
#8
Correcto
0.517 s 23 KBi
#9
Tiempo límite excedido
1.037 s 35 KBi
#10
Tiempo límite excedido
1.053 s 31 KBi
#11
Tiempo límite excedido
1.042 s 35 KBi
#12
Tiempo límite excedido
1.122 s 35 KBi
#13
Tiempo límite excedido
1.023 s 38 KBi
#14
Tiempo límite excedido
1.027 s 36 KBi
Puntos totales: 58 / 100

Código

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

/**
 *
 * @author Julian_Miranda
 */
public class Main {

    static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) throws IOException {
        long n = Long.parseLong(bf.readLine());
        long[] arreglo = Arrays.stream(bf.readLine().split(" ")).mapToLong(x -> Long.parseLong(x)).toArray();
        long m = Long.parseLong(bf.readLine());
        for (int i = 0; i < m; i++) {
            long[] cases = Arrays.stream(bf.readLine().split(" ")).mapToLong(x -> Long.parseLong(x)).toArray();
            if (cases[0] == cases[1]) {
                System.out.println(arreglo[(int)cases[0]]);
            }else{
                long sum = 0;
                for (int j = (int)cases[0]; j <= cases[1]; j++) {
                    sum += arreglo[j];
                }
                System.out.println(sum);
            }
        }
    }
}