문제링크
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() }
val boxes = mutableListOf<List<Int>>()
for (i in 0 until n) {
boxes.add(bufferedReader.readLine().split(" ").map { it.toInt() })
}
val isMaxHeight = Array(n) { Array(m) { false } }
for (i in 0 until m) {
var maxHeightIndex = 0
for (j in 0 until n) {
if (boxes[j][i] > boxes[maxHeightIndex][i]) {
maxHeightIndex = j
}
}
isMaxHeight[maxHeightIndex][i] = true
}
for (i in 0 until n) {
var maxHeightIndex = 0
for (j in 0 until m) {
if (boxes[i][j] > boxes[i][maxHeightIndex]) {
maxHeightIndex = j
}
}
isMaxHeight[i][maxHeightIndex] = true
}
var removedBoxes = 0L
for (i in 0 until n) {
for (j in 0 until m) {
if (!isMaxHeight[i][j]) {
removedBoxes += boxes[i][j]
}
}
}
bufferedWriter.write("$removedBoxes")
bufferedReader.close()
bufferedWriter.close()
}