1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-14 01:49:41 +01:00
LeetCode/go/most-profit-assigning-work.go
Matej Focko 8faeaa7e16
go: add «826. Most Profit Assigning Work»
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-06-18 12:10:43 +02:00

28 lines
460 B
Go

package main
import (
"slices"
)
func maxProfitAssignment(difficulty []int, profit []int, worker []int) int {
maxAbility := slices.Max(worker)
jobs := make([]int, maxAbility+1)
for i, d := range difficulty {
if d > maxAbility {
continue
}
jobs[d] = max(jobs[d], profit[i])
}
for i := 1; i <= maxAbility; i++ {
jobs[i] = max(jobs[i], jobs[i-1])
}
total := 0
for _, ability := range worker {
total += jobs[ability]
}
return total
}