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

Envío 4060

Problema 0x25 - Suma de un subarreglo grande

  • Autor: juanboterog
  • Fecha: 2021-05-02 17:08:48 UTC (Hace casi 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.174 s 14 KBi
#2
Correcto
0.125 s 16 KBi
#3
Correcto
0.134 s 14 KBi
#4
Correcto
0.147 s 14 KBi
#5
Correcto
0.126 s 17 KBi
#6
Correcto
0.194 s 14 KBi
#7
Correcto
0.205 s 14 KBi
#8
Correcto
0.579 s 44 KBi
#9
Tiempo límite excedido
1.104 s 56 KBi
#10
Tiempo límite excedido
1.046 s 57 KBi
#11
Tiempo límite excedido
1.162 s 58 KBi
#12
Tiempo límite excedido
1.021 s 68 KBi
#13
Tiempo límite excedido
1.092 s 95 KBi
#14
Tiempo límite excedido
1.079 s 79 KBi
Puntos totales: 58 / 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[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        int c = scanner.nextInt();
        for (int k = 0; k < c; k++) {
            int p = scanner.nextInt();
            int q = scanner.nextInt();
            solve(a, p, q);
        }
    }

    private static void solve(int[] a, int p, int q) {
        int sum = 0;
        for (int i = p; i <= q; i++) {
            sum += a[i];
        }
        System.out.println(sum);
    }
}