Skip to content

Commit

Permalink
solve: 이모티콘 할인행사
Browse files Browse the repository at this point in the history
  • Loading branch information
bngsh committed Feb 25, 2024
1 parent 114dec4 commit 20ff493
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/main/kotlin/byeonghee/week51/이모티콘 할인행사.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package byeonghee.week51

class 소병희_이모티콘할인행사 {

val answer = IntArray(2)
val discounts = 10..40 step 10

lateinit var users: Array<IntArray>
lateinit var emoticons: IntArray

fun solution(_users: Array<IntArray>, _emoticons: IntArray): IntArray {
users = _users
emoticons = _emoticons

recursiveDiscount(0, IntArray(users.size))

return answer
}

fun recursiveDiscount(idx: Int, shopped: IntArray) {
if (idx == emoticons.size) {
var plus = 0
var gain = 0

for(bill in shopped) {
if (bill == -1) plus++
else gain += bill
}

if (answer[0] < plus) {
answer[0] = plus
answer[1] = gain
}
else if (answer[0] == plus && answer[1] < gain) {
answer[1] = gain
}
return
}

for(discount in discounts) {
var newPrice = emoticons[idx] / 100 * (100 - discount)
val newShopped = shopped.clone()

for((user, data) in users.withIndex()) {
val (ratio, budget) = data
if (shopped[user] == -1) continue
if (discount >= ratio) {
newShopped[user] += newPrice
if (newShopped[user] >= budget) {
newShopped[user] = -1
}
}
}

recursiveDiscount(idx + 1, newShopped)
}
}
}

0 comments on commit 20ff493

Please sign in to comment.