go: add «2530. Maximal Score After Applying K Operations»

URL:	https://leetcode.com/problems/maximal-score-after-applying-k-operations/
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2024-10-14 17:22:20 +02:00
parent b50a4be64f
commit ac642f72d7
Signed by: mfocko
SSH key fingerprint: SHA256:icm0fIOSJUpy5+1x23sfr+hLtF9UhY8VpMC7H4WFJP8

View file

@ -0,0 +1,34 @@
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
}