forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0826.java
22 lines (22 loc) · 778 Bytes
/
0826.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Solution {
public int maxProfitAssignment(int[] difficulty, int[] profit, int[] worker) {
List<int[]> jobs = new ArrayList();
int N = profit.length, res = 0, i = 0, best = 0;
for (int j = 0; j < N; ++j)
jobs.add(new int[]{difficulty[j], profit[j]});
Collections.sort(jobs, new Comparator<int[]>() {
@Override
public int compare(int[] o1, int[] o2) {
if (o1[0] == o2[0]) return o1[1] - o2[1];
return o1[0] - o2[0];
}
});
Arrays.sort(worker);
for (int w : worker) {
while (i < N && w >= jobs.get(i)[0])
best = Math.max(jobs.get(i++)[1], best);
res += best;
}
return res;
}
}