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

Envío 533

Problema 0x25 - Suma de un subarreglo grande

  • Autor: edwaraco
  • Fecha: 2020-09-07 01:36:12 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.152 s 12 KBi
#2
Correcto
0.159 s 12 KBi
#3
Correcto
0.156 s 14 KBi
#4
Correcto
0.155 s 12 KBi
#5
Correcto
0.142 s 13 KBi
#6
Correcto
0.193 s 15 KBi
#7
Correcto
0.22 s 20 KBi
#8
Correcto
0.383 s 25 KBi
#9
Correcto
0.574 s 34 KBi
#10
Correcto
0.568 s 36 KBi
#11
Tiempo límite excedido
0.338 s 22 KBi
#12
Tiempo límite excedido
0.335 s 22 KBi
#13
Correcto
0.565 s 35 KBi
#14
Tiempo límite excedido
0.331 s 21 KBi
Puntos totales: 79 / 100

Código

import java.util.Scanner;

public class Main {

    public static int[] processLine(int N, Scanner myObj) {
        int elements[] = new int[N];
        elements[0] = myObj.nextInt();
        for (int i=1; i < N; i++) {
            elements[i] = elements[i-1] + myObj.nextInt();
        }
        return elements;
    }

    public static void main(String ...args) {
        int N, C, from, to, sum;
        int[] elements;
        Scanner myObj = new Scanner(System.in);
        N = myObj.nextInt();
        elements = processLine(N, myObj);
        C = myObj.nextInt();
        for (int i = 0; i < C; i++) {
            from = myObj.nextInt();
            to = myObj.nextInt();
            sum = elements[to];
            if (from - 1 >= 0) sum -= elements[from - 1];
            System.out.println(sum);
        }
    }
}