[백준] Piece of Cake! (17874)(kotlin)

문제 설명

백준 17874번 문제 링크

입력 및 출력

» 입력

The input consists of a single line containing three integers n (2 ≤ n ≤ 10 000), the length of the sides of the square cake in centimeters, h (0 < h < n), the distance of the horizontal cut from the top edge of the cake in centimeters, and v (0 < v < n), the distance of the vertical cut from the left edge of the cake in centimeters. This is illustrated in the figure above. Each cake is 4 centimeters thick.

» 출력

Display the volume (in cubic centimeters) of the largest of the four pieces of cake after the horizontal and vertical cuts are made.

예제 입출력

입력 출력
10 4 7 168
5 2 2 36
4 2 1 24

문제 풀이1

import java.util.Scanner

fun main(args: Array<String>) = with(Scanner(System.`in`)) {
    val n = nextInt()
    val h = nextInt()
    val v = nextInt()

    println(
        MutableList<Int>(4) {
            when (it) {
                0 -> h * v * 4
                1 -> (n - h) * v * 4
                2 -> h * (n - v) * 4
                else -> (n - h) * (n - v) * 4
            }
        }.maxOf { it }
    )
}