diff --git "a/src/main/kotlin/heejik/13week/\360\237\220\234 \352\270\260\354\240\201\354\235\230 \353\247\244\353\247\244\353\262\225 \360\237\220\234.kt" "b/src/main/kotlin/heejik/13week/\360\237\220\234 \352\270\260\354\240\201\354\235\230 \353\247\244\353\247\244\353\262\225 \360\237\220\234.kt" new file mode 100644 index 00000000..b9473c24 --- /dev/null +++ "b/src/main/kotlin/heejik/13week/\360\237\220\234 \352\270\260\354\240\201\354\235\230 \353\247\244\353\247\244\353\262\225 \360\237\220\234.kt" @@ -0,0 +1,71 @@ +package heejik.`13week` + +class `🐜 기적의 맀맀법 🐜` { + + fun solve() { + val money = readln().toInt() + val stocks = readln().split(' ').map { it.toInt() } + + val bnf = bnf(money, stocks) + val timing = timing(money, stocks) + + println( + if (bnf > timing) "BNP" + else if (timing > bnf) "TIMING" + else "SAMESAME" + ) + } + + private fun bnf(_money: Int, stocks: List): Int { + var money = _money + var stock = 0 + + stocks.forEach { + val cnt = money / it + money -= it * (cnt) + stock += cnt + } + + return money + (stock * stocks.last()) + } + + private fun timing(_money: Int, stocks: List): Int { + var money = _money + var stock = 0 + + var upCnt = 0 + var downCnt = 0 + var preStock = stocks.first() + + stocks.drop(0).forEach { + if (it > preStock) { + upCnt++ + downCnt = 0 + } else if (it < preStock) { + downCnt++ + upCnt = 0 + } else { + upCnt = 0 + downCnt = 0 + } + + if (upCnt >= 3) { + money += stock * it + stock = 0 + } + if (downCnt >= 3) { + val cnt = money / it + money -= it * (cnt) + stock += cnt + } + + preStock = it + } + + return money + (stock * stocks.last()) + } +} + +fun main() { + `🐜 기적의 맀맀법 🐜`().solve() +} \ No newline at end of file