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

Envío 1394

Problema 0x25 - Suma de un subarreglo grande

  • Autor: judavid.arias
  • Fecha: 2020-10-25 01:37:00 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.065 s 10 KBi
#2
Correcto
0.089 s 11 KBi
#3
Correcto
0.079 s 10 KBi
#4
Correcto
0.083 s 11 KBi
#5
Correcto
0.089 s 11 KBi
#6
Correcto
0.105 s 11 KBi
#7
Correcto
0.084 s 10 KBi
#8
Correcto
0.535 s 19 KBi
#9
Correcto
0.991 s 34 KBi
#10
Tiempo límite excedido
1.051 s 35 KBi
#11
Tiempo límite excedido
1.095 s 36 KBi
#12
Correcto
0.579 s 26 KBi
#13
Tiempo límite excedido
1.068 s 39 KBi
#14
Tiempo límite excedido
1.013 s 33 KBi
Puntos totales: 72 / 100

Código

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


public class Main {


    public static void main(String[] args) throws IOException {
        BufferedReader reader =
                new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(reader.readLine());
        int []array = new int[N];

        int []sums = new int[N];
        int sum = 0;
        StringTokenizer tk = new StringTokenizer(reader.readLine());
        int i =0;
        while(tk.hasMoreTokens()){
            array[i] = Integer.parseInt(tk.nextToken());
            sum += array[i];
            sums[i] = sum;
            i++;
        }

        int c = Integer.parseInt(reader.readLine());
        for(i = 0;i<c;i++){
            tk = new StringTokenizer(reader.readLine());
            int p = Integer.parseInt(tk.nextToken());
            int q = Integer.parseInt(tk.nextToken());
            int result = sums[q]-sums[p]+array[p];
            System.out.println(result);
        }

    }

}