Simple JAVA solution
Approach : \n1. bind profit & difficulty array together using a simple 2d-array \'pair\'.\n2.  sort pair array on basis of difficulty column.\n3.  sort worker a
**Approach** : \n1. bind profit & difficulty array together using a simple 2d-array \'pair\'.\n2.  sort pair array on basis of difficulty column.\n3.  sort worker array.\n3.  for each worker, find his maximum profit best he can make under his ability.\n\n**Doubt** :\nWhat is the need to sort worker[ ] ???\n**Reason** :\nIf current worker has more capacity than his previous ones, then his minimum bestPay should be equal to, maximum bestPaySoFar of workers with less capacity.\nIf he\'s able to do more-tougher-job, but less-tougher-job pays more, then he\'s automatically entitled to benefits of that less-tougher-job.\nNow because he has more ability as compared to previous workers, he can explore more tougher-high-paying-jobs.\n\nDue to this, we need to traverse pair[ ] only once.\nthough we have nested for-while loop, but complexity will become o[worker.length] + o[pair.length].\n\nOverall time complexity:\ndue to sorting of both worker & pair : O(PlogP + WlogW).\n\n**Java**:\n```\npublic int maxProfitAssignment(int[] diff, int[] profit, int[] worker) {`\n\n\tint pair[][] = new int[diff.length][2];\n\tfor(int i = 0; i < diff.length; i++){\n\t\tpair[i][0] = diff[i];\n\t\tpair[i][1] = profit[i];\n\t}\n\t// sorting 2d array on basis of difficulty colmn\n\tArrays.sort(pair, new Comparator<int[]>() {\n\t\t@Override\n\t\tpublic int compare(int o1[], int o2[]){\n\t\t\treturn Integer.valueOf(o1[0]).compareTo(o2[0]);\n\t\t}\n\t});\n\n\tint totalProfit = 0;\n\n\t//MAGIC begins HERE\n\tArrays.sort(worker);\n\tint bestPaySoFar = 0;\n\tint i = 0;      // declaring globally creates MAGIC!!\n\n\tfor(int k = 0; k < worker.length; k++){\n\t\tint ability = worker[k];\n\n\t\twhile(i < pair.length && ability >= pair[i][0]){\n\t\t\tif(bestPaySoFar < pair[i][1])\n\t\t\t\tbestPaySoFar = pair[i][1];\n\t\t\ti++;\n\t\t}\n\n\t\ttotalProfit += bestPaySoFar;\n\t}\n\n\treturn totalProfit;\n}\n```
['Sorting', 'Java']