목차
[백준][Java] -
[프로그래머스][Kotlin] -
문제 정보
https://codeforces.com/problemset/problem/466/A
Problem - 466A - Codeforces
codeforces.com
난이도 : A
유형 : 그리디, Math
문제 풀이
세트의 표의 1장당 가격 vs 일반 1장당 가격
둘이 비교해서 그리디 하게 선택하면 된다.
코드
import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.StringTokenizer
fun solution() = with(BufferedReader(InputStreamReader(System.`in`))) {
var st = StringTokenizer(readLine())
var n = st.nextToken().toInt()
var m = st.nextToken().toInt()
var a = st.nextToken().toDouble()
var b = st.nextToken().toDouble()
var res: Double = 0.0
if (a > b / m) {
res += n / m * b
n %= m
if (n > 0) {
if (a * n < b) {
res += a * n
} else {
res += b
}
}
} else {
res = n * a
}
println(res.toInt())
}
fun main() {
solution()
}
'Algorithm, Problem Solving > codeforces' 카테고리의 다른 글
[codeforces][Kotlin] 703A - Mishka and Game (0) | 2023.03.28 |
---|---|
[codeforces][Kotlin] 313A - Ilya and Bank Account (0) | 2023.03.27 |
[codeforces][Kotlin] 189A - Cut Ribbon (0) | 2023.03.24 |
[Codeforces][Kotlin] 1796A - Typical Interview Problem (0) | 2023.03.22 |
[Codeforces][Kotlin] 32B - Borze (0) | 2023.03.21 |
댓글