Java Solution with TreeMap
```\npublic int maxProfitAssignment(int[] difficulty, int[] profit, int[] worker) {\n       \n        TreeMap tmap = new TreeMap<>();\n        // in case two jo
```\npublic int maxProfitAssignment(int[] difficulty, int[] profit, int[] worker) {\n       \n        TreeMap<Integer, Integer> tmap = new TreeMap<>();\n        // in case two jobs have same difficulty but different profit, we want to count\n        // the higher profit\n        for (int i = 0; i < difficulty.length; i++) {\n            tmap.put(difficulty[i], Math.max(profit[i], tmap.getOrDefault(difficulty[i], 0)));\n        }\n\n        int max = 0, res = 0;\n        // maximum profit at this difficulty or below in case\n        // lower difficulty job offers higher profit\n        for (Integer key : tmap.keySet()) {\n            max = Math.max(tmap.get(key), max);\n            tmap.put(key, max);\n        }\n        \n        Map.Entry<Integer, Integer> entry = null;\n        for (int i = 0; i < worker.length; i++) {\n            if (tmap.containsKey(worker[i])) {\n                res += tmap.get(worker[i]);\n            } else {\n                entry = tmap.floorEntry(worker[i]);            \n                if (entry != null) {\n                    res += entry.getValue();\n                }\n            }  \n        }\n        return res;  \n}
[]