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

Envío 1740

Problema 0x25 - Suma de un subarreglo grande

  • Autor: JulianMi12
  • Fecha: 2020-11-06 19:39:50 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Incorrecto
0.121 s 12 KBi
#2
Incorrecto
0.119 s 12 KBi
#3
Incorrecto
0.095 s 12 KBi
#4
Incorrecto
0.107 s 12 KBi
#5
Incorrecto
0.11 s 12 KBi
#6
Incorrecto
0.124 s 12 KBi
#7
Incorrecto
0.13 s 12 KBi
#8
Incorrecto
0.545 s 25 KBi
#9
Tiempo límite excedido
1.015 s 29 KBi
#10
Tiempo límite excedido
1.0 s 31 KBi
#11
Tiempo límite excedido
1.025 s 32 KBi
#12
Tiempo límite excedido
1.043 s 32 KBi
#13
Incorrecto
0.714 s 38 KBi
#14
Tiempo límite excedido
1.057 s 36 KBi
Puntos totales: 0 / 100

Código

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

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

    static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter br = new BufferedWriter(new OutputStreamWriter(System.out));

    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();
            find(arreglo, cases);
        }
    }

    public static void find(long[] arreglo, long[] cases) throws IOException {
        if (cases[0] == cases[1]) {
            br.write(String.valueOf(arreglo[(int) cases[0]]));
        } else {
            long sum = 0;
            for (int j = (int) cases[0]; j <= cases[1]; j++) {
                sum += arreglo[j];
            }
            br.write(String.valueOf(sum));
        }
    }
}