mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-10 00:09:06 +01:00
go: add «826. Most Profit Assigning Work»
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
e74d5bfa99
commit
8faeaa7e16
1 changed files with 28 additions and 0 deletions
28
go/most-profit-assigning-work.go
Normal file
28
go/most-profit-assigning-work.go
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
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
|
||||||
|
}
|
Loading…
Reference in a new issue