Java AC, sort and binary search, O(nlogn)
\nclass Solution {\n    class Pair {\n        int d;\n        int p;\n        public Pair(int d, int p) {\n            this.d = d;\n            this.p = p;\n   
```\nclass Solution {\n    class Pair {\n        int d;\n        int p;\n        public Pair(int d, int p) {\n            this.d = d;\n            this.p = p;\n        }\n    }\n\n    public int maxProfitAssignment(int[] difficulty, int[] profit, int[] worker) {\n        List<Pair> list = new ArrayList<>();\n        for (int i = 0; i < profit.length; i++) {\n            list.add(new Pair(difficulty[i], profit[i]));\n        }\n\n        // sort d from small to large and if d is the same, put smaller p in the front\n        Collections.sort(list, (a, b) -> (a.d == b.d) ? a.p - b.p : a.d - b.d);\n\n        for (int i = 1; i < list.size(); i++) {\n            // assign the max profit from 0 to current location\n            list.get(i).p = Math.max(list.get(i).p, list.get(i - 1).p);\n        }\n\n        int count = 0;\n        for (int w : worker) {\n            count += binarySearch(list, w);\n        }\n\n        return count;\n    }\n\n    // find the last number <= w in list.d, and return that index\'s profit, if not available return 0.\n    private int binarySearch(List<Pair> list, int w) {\n        int start = 0;\n        int end = list.size() - 1;\n        while (start + 1 < end) {\n            int mid = (end - start) / 2 + start;\n            if (list.get(mid).d <= w) {\n                start = mid;\n            } else {\n                end = mid;\n            }\n        }\n\n        if (list.get(end).d <= w) {\n            return list.get(end).p;\n        }\n        if (list.get(start).d <= w) {\n            return list.get(start).p;\n        }\n        return 0;\n    }\n}\n```
[]