Skip to content

Commit

Permalink
Merge pull request #60 from AlgoLeadMe/16-SeongHoonC
Browse files Browse the repository at this point in the history
16-SeongHoonC
  • Loading branch information
SeongHoonC authored Mar 28, 2024
2 parents 4b70a31 + 8e10115 commit f8bc67d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions SeongHoonC/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
| 13์ฐจ์‹œ | 2024.03.03 | bfs | <a href="https://www.acmicpc.net/problem/14940"></a> |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/49 |
| 14์ฐจ์‹œ | 2024.03.06 | dfs | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/64064"></a> |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/50 |
| 15์ฐจ์‹œ | 2024.03.09 | ๋ถ„ํ• ์ •๋ณต | <a href="https://www.acmicpc.net/problem/1629"></a> |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/55 |
| 16์ฐจ์‹œ | 2024.03.14 | ๋ˆ„์ ํ•ฉ | <a href="https://www.acmicpc.net/problem/11659"></a> |https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/60 |
---
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 f8bc67d

Please sign in to comment.