1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| class Solution { public int maxProfitAssignment(int[] difficulty, int[] profit, int[] worker) { int n = difficulty.length; int[][] index = new int[n][2]; for (int i = 0; i < n; ++i) { index[i] = new int[]{difficulty[i], profit[i]}; } Arrays.sort(index, (a, b) -> a[0] - b[0]); Arrays.sort(worker); int ans = 0, j = 0, maxProfit = 0; for (int w : worker) { while (j < n && index[j][0] <= w) { maxProfit = Math.max(maxProfit, index[j++][1]); } ans += maxProfit; } return ans; } }
|