forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0826.go
More file actions
29 lines (28 loc) · 706 Bytes
/
0826.go
File metadata and controls
29 lines (28 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
func maxProfitAssignment(difficulty []int, profit []int, worker []int) int {
jobs := make([][]int, 0)
N, res, i, best := len(profit), 0, 0, 0
for j := 0; j < N; j++ {
jobs = append(jobs, []int{difficulty[j], profit[j]})
}
sort.Slice(jobs, func(i, j int) bool {
if jobs[i][0] == jobs[j][0] {
return jobs[i][1] < jobs[j][1]
}
return jobs[i][0] < jobs[j][0]
})
sort.Ints(worker)
for _, w := range worker {
for i < N && w >= jobs[i][0] {
best = max(best, jobs[i][1])
i++
}
res += best
}
return res
}
func max(a, b int) int {
if a > b {
return a
}
return b
}