1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-10-18 06:42:08 +02:00
LeetCode/go/maximal-score-after-applying-k-operations.go

34 lines
533 B
Go

package main
import (
"cmp"
pq "github.com/emirpasic/gods/v2/queues/priorityqueue"
)
func maxKelements(nums []int, k int) int64 {
intCeil := func(whole, remainder int) int {
if remainder != 0 {
return whole + 1
}
return whole
}
descending := func(a, b int) int {
return -cmp.Compare(a, b)
}
q := pq.NewWith(descending)
for _, x := range nums {
q.Enqueue(x)
}
score := int64(0)
for i := 0; i < k; i++ {
num, _ := q.Dequeue()
score += int64(num)
q.Enqueue(intCeil(num/3, num%3))
}
return score
}