문제링크
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() }
var minPack = Int.MAX_VALUE
var minPiece = Int.MAX_VALUE
for (i in 0 until m) {
val (pack, piece) = bufferedReader
.readLine()
.split(" ")
.map { it.toInt() }
if (pack < minPack) minPack = pack
if (piece < minPiece) minPiece = piece
}
if (minPack >= minPiece * 6) bufferedWriter.write("${minPiece * n}")
else {
var total = 0
total += minPack * (n / 6)
val remain = n % 6
total += if (minPack > minPiece * remain) minPiece * remain
else minPack
bufferedWriter.write("$total")
}
bufferedReader.close()
bufferedWriter.close()
}