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

Envío 773

Problema 0x25 - Suma de un subarreglo grande

  • Autor: pepradere
  • Fecha: 2020-09-16 01:59:28 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Error de compilación
                      Compilation time limit exceeded.
                    
#2
Error de compilación
                      Compilation time limit exceeded.
                    
#3
Error de compilación
                      Compilation time limit exceeded.
                    
#4
Error de compilación
                      Compilation time limit exceeded.
                    
#5
Error de compilación
                      Compilation time limit exceeded.
                    
#6
Correcto
0.099 s 20 KBi
#7
Error de compilación
                      Compilation time limit exceeded.
                    
#8
Error de compilación
                      Compilation time limit exceeded.
                    
#9
Correcto
0.457 s 31 KBi
#10
Correcto
0.575 s 23 KBi
#11
Correcto
0.39 s 26 KBi
#12
Correcto
0.528 s 22 KBi
#13
Correcto
0.433 s 28 KBi
#14
Correcto
0.508 s 25 KBi
Puntos totales: 50 / 100

Código

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        for (String ln; (ln = in.readLine()) != null; ) {
            int N = Integer.parseInt(ln);
            int[] arr = new int[N];
            StringTokenizer st = new StringTokenizer(in.readLine());
            for (int i = 0; i < N; ++i) {
                arr[i] = Integer.parseInt(st.nextToken());
                if (i > 0) {
                    arr[i] += arr[i - 1];
                }
            }
            int q = Integer.parseInt(in.readLine());
            StringBuilder sb = new StringBuilder();
            while (q-- > 0) {
                st = new StringTokenizer(in.readLine());
                int f = Integer.parseInt(st.nextToken());
                int t = Integer.parseInt(st.nextToken());
                int sol = 0;
                if (f == 0) {
                    sol = arr[t];
                } else {
                    sol = arr[t] - arr[f - 1];
                }
                sb.append(sol).append("\n");
            }
            System.out.print(new String(sb));
        }
    }
}