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

Envío 584

Problema 0x25 - Suma de un subarreglo grande

  • Autor: Mejibyte
  • Fecha: 2020-09-08 03:34:09 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Error en tiempo de ejecución (NZEC)
Exited with error status 1
  File "script.py", line 1
    // Solution to https://codeo.app/problemas/0x25-suma-de-un-subarreglo
    ^
SyntaxError: invalid syntax
0.023 s 3 KBi
#2
Error en tiempo de ejecución (NZEC)
Exited with error status 1
  File "script.py", line 1
    // Solution to https://codeo.app/problemas/0x25-suma-de-un-subarreglo
    ^
SyntaxError: invalid syntax
0.022 s 3 KBi
#3
Error en tiempo de ejecución (NZEC)
Exited with error status 1
  File "script.py", line 1
    // Solution to https://codeo.app/problemas/0x25-suma-de-un-subarreglo
    ^
SyntaxError: invalid syntax
0.024 s 3 KBi
#4
Error en tiempo de ejecución (NZEC)
Exited with error status 1
  File "script.py", line 1
    // Solution to https://codeo.app/problemas/0x25-suma-de-un-subarreglo
    ^
SyntaxError: invalid syntax
0.019 s 3 KBi
#5
Error en tiempo de ejecución (NZEC)
Exited with error status 1
  File "script.py", line 1
    // Solution to https://codeo.app/problemas/0x25-suma-de-un-subarreglo
    ^
SyntaxError: invalid syntax
0.026 s 3 KBi
#6
Error en tiempo de ejecución (NZEC)
Exited with error status 1
  File "script.py", line 1
    // Solution to https://codeo.app/problemas/0x25-suma-de-un-subarreglo
    ^
SyntaxError: invalid syntax
0.021 s 3 KBi
#7
Error en tiempo de ejecución (NZEC)
Exited with error status 1
  File "script.py", line 1
    // Solution to https://codeo.app/problemas/0x25-suma-de-un-subarreglo
    ^
SyntaxError: invalid syntax
0.02 s 3 KBi
#8
Error en tiempo de ejecución (NZEC)
Exited with error status 1
  File "script.py", line 1
    // Solution to https://codeo.app/problemas/0x25-suma-de-un-subarreglo
    ^
SyntaxError: invalid syntax
0.026 s 3 KBi
#9
Error en tiempo de ejecución (NZEC)
Exited with error status 1
  File "script.py", line 1
    // Solution to https://codeo.app/problemas/0x25-suma-de-un-subarreglo
    ^
SyntaxError: invalid syntax
0.028 s 3 KBi
#10
Error en tiempo de ejecución (NZEC)
Exited with error status 1
  File "script.py", line 1
    // Solution to https://codeo.app/problemas/0x25-suma-de-un-subarreglo
    ^
SyntaxError: invalid syntax
0.02 s 3 KBi
#11
Error en tiempo de ejecución (NZEC)
Exited with error status 1
  File "script.py", line 1
    // Solution to https://codeo.app/problemas/0x25-suma-de-un-subarreglo
    ^
SyntaxError: invalid syntax
0.019 s 3 KBi
#12
Error en tiempo de ejecución (NZEC)
Exited with error status 1
  File "script.py", line 1
    // Solution to https://codeo.app/problemas/0x25-suma-de-un-subarreglo
    ^
SyntaxError: invalid syntax
0.027 s 3 KBi
#13
Error en tiempo de ejecución (NZEC)
Exited with error status 1
  File "script.py", line 1
    // Solution to https://codeo.app/problemas/0x25-suma-de-un-subarreglo
    ^
SyntaxError: invalid syntax
0.02 s 3 KBi
#14
Error en tiempo de ejecución (NZEC)
Exited with error status 1
  File "script.py", line 1
    // Solution to https://codeo.app/problemas/0x25-suma-de-un-subarreglo
    ^
SyntaxError: invalid syntax
0.019 s 3 KBi
Puntos totales: 0 / 100

Código

// Solution to https://codeo.app/problemas/0x25-suma-de-un-subarreglo
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func solve(a, s []int, p, q int) {
	// O(1)
	sum := s[q] // a[0] + a[1] + ... + a[q]
	if p-1 >= 0 {
		sum -= s[p-1]
	}

	// Alternatively, this works too, and some people might like it more.
	// sum := s[q] - s[p] + a[p];
	fmt.Println(sum)
}

func main() {

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())

	a := make([]int, n)
	s := make([]int, n)
	sum := 0
	for i := 0; i < n; i++ {
		scanner.Scan()
		a[i], _ = strconv.Atoi(scanner.Text())
		sum += a[i]
		s[i] = sum
	}

	// s[i] = sum of a[0] + ... + a[i]
	var c int
	scanner.Scan()
	c, _ = strconv.Atoi(scanner.Text())

	for k := 0; k < c; k++ {
		var p, q int

		scanner.Scan()
		p, _ = strconv.Atoi(scanner.Text())
		scanner.Scan()

		q, _ = strconv.Atoi(scanner.Text())
		solve(a, s, p, q)
	}
}