Skip to content

Commit

Permalink
feat: 우체국 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
soopeach committed Mar 13, 2024
1 parent c596fb1 commit 1f29f8f
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/main/kotlin/hyunsoo/54week/우체국.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package hyunsoo.`54week`

/**
*
* <문제>
* [우체국](https://www.acmicpc.net/problem/2141)
*
* - 아이디어
*
* - 트러블 슈팅
*
*/
class `전현수_우체국` {

private data class VillageInfo(val villageNum: Long, val peopleCnt: Long)

private val villageInfoList = mutableListOf<VillageInfo>()

fun solution() {

var totalPeopleCnt = 0L
var prefixSumOfPeopleCnt = 0L
val n = readln().toInt()

repeat(n) {

val (villageNum, peopleCnt) = readln().split(" ").map { it.toLong() }
villageInfoList.add(VillageInfo(villageNum, peopleCnt))
totalPeopleCnt += peopleCnt

}

val mid = if (totalPeopleCnt % 2 == 0L) totalPeopleCnt / 2 else totalPeopleCnt / 2 + 1

villageInfoList
.sortedBy { it.villageNum }
.forEach {

val (vil, curPeopleCnt) = it

prefixSumOfPeopleCnt += curPeopleCnt

if (mid <= prefixSumOfPeopleCnt) {
println(vil)
return
}
}
}
}

fun main() {
전현수_우체국().solution()
}

0 comments on commit 1f29f8f

Please sign in to comment.