Skip to content

Commit

Permalink
2024-03-14 solved
Browse files Browse the repository at this point in the history
  • Loading branch information
SeongHoonC committed Mar 14, 2024
1 parent 90f160c commit 8e10115
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import java.io.BufferedReader
import java.io.BufferedWriter
import java.io.InputStreamReader
import java.io.OutputStreamWriter

fun main() {
val br = BufferedReader(InputStreamReader(System.`in`))
val bw = BufferedWriter(OutputStreamWriter(System.out))
val (n, m) = br.readLine().split(" ").map { it.toInt() }
val nums = br.readLine().split(" ").map { it.toInt() }
val addedSum = Array(n + 1) { 0 }
addedSum[1] = nums[0]

// i ๊นŒ์ง€ ๋ˆ„์ ํ•ฉ ๊ตฌํ•˜๊ธฐ
for (i in 2..n) {
addedSum[i] = addedSum[i - 1] + nums[i - 1]
}

// ๋ˆ„์ ํ•ฉ end ์—์„œ ๋ˆ„์ ํ•ฉ start - 1 ๋ฅผ ๋นผ์„œ start ~ end ๊ตฌ๊ฐ„ ํ•ฉ ๊ตฌํ•˜๊ธฐ
for (i in 0 until m) {
val (start, end) = br.readLine().split(" ").map { it.toInt() }
bw.write((addedSum[end] - addedSum[start - 1]).toString())
bw.newLine()
}
// BufferedWriter ๋กœ ํ•œ๋ฒˆ์— ์ถœ๋ ฅ
bw.flush()
bw.close()
}

0 comments on commit 8e10115

Please sign in to comment.