문제링크
import java.io.BufferedReader
import java.io.BufferedWriter
private lateinit var bufferedReader: BufferedReader
private lateinit var bufferedWriter: BufferedWriter
fun main() {
bufferedReader = System.`in`.bufferedReader()
bufferedWriter = System.out.bufferedWriter()
val (n, m) = bufferedReader
.readLine()
.split(" ")
.map { it.toInt() }
val numbers = bufferedReader
.readLine()
.split(" ")
.map { it.toInt() }
.toMutableList()
for (i in 1 until n) {
numbers[i] += numbers[i - 1]
}
repeat(m) {
val (i, j) = bufferedReader
.readLine()
.split(" ")
.map { it.toInt() }
if (i - 2 < 0) bufferedWriter.write("${numbers[j - 1]}\n")
else bufferedWriter.write("${numbers[j - 1] - numbers[i - 2]}\n")
}
bufferedReader.close()
bufferedWriter.close()
}