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 { type work struct { d int p int } n := len(difficulty) arr := make([]work, n) for i := 0; i < n; i++ { arr[i] = work{ d: difficulty[i], p: profit[i], } } sort.Slice(arr, func(i, j int) bool { return arr[i].d <= arr[j].d }) sort.Ints(worker) ans := 0 i := 0 maxVal := 0 for _, w := range worker { for i < n && w >= arr[i].d { maxVal = max(maxVal, arr[i].p) i++ } ans += maxVal } return ans }
|