Instantly share code, notes, and snippets.

@dfyz /1330.go
Created Jan 24, 2013

Embed
What would you like to do?
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
in := bufio.NewReader(os.Stdin)
out := bufio.NewWriter(os.Stdout)
defer out.Flush()
var n int
fmt.Fscan(in, &n)
sum := make([]int, n + 1)
var k int
for i := 0; i < n; i++ {
fmt.Fscan(in, &k)
sum[i + 1] = sum[i] + k
}
var m int
fmt.Fscan(in, &m)
var from, to int
for i := 0; i < m; i++ {
fmt.Fscan(in, &from, &to)
fmt.Fprintln(out, sum[to] - sum[from - 1])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment