From 8faeaa7e1621a88362c5f4c6533fbd4e05cefadd Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Tue, 18 Jun 2024 12:10:43 +0200 Subject: [PATCH] =?UTF-8?q?go:=20add=20=C2=AB826.=20Most=20Profit=20Assign?= =?UTF-8?q?ing=20Work=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matej Focko --- go/most-profit-assigning-work.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 go/most-profit-assigning-work.go diff --git a/go/most-profit-assigning-work.go b/go/most-profit-assigning-work.go new file mode 100644 index 0000000..e27ab95 --- /dev/null +++ b/go/most-profit-assigning-work.go @@ -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 +}