mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-01-12 18:08:38 +08:00
routine
This commit is contained in:
19
25/12/go/3075.go
Normal file
19
25/12/go/3075.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package A
|
||||||
|
|
||||||
|
import (
|
||||||
|
"slices"
|
||||||
|
)
|
||||||
|
|
||||||
|
func maximumHappinessSum(happiness []int, k int) int64 {
|
||||||
|
ans := int64(0)
|
||||||
|
slices.SortFunc(happiness, func(a, b int) int {
|
||||||
|
return b - a
|
||||||
|
})
|
||||||
|
for i, v := range happiness {
|
||||||
|
if v < i || i > k-1 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
ans += int64(v - i)
|
||||||
|
}
|
||||||
|
return ans
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user