[Javascript] Subproblems and Preprocessing
Sort the difficulties and workers, then get the maximum profit you can get at that difficulty (which includes any lower difficulties).\nUse i,j counter to find 
Sort the difficulties and workers, then get the maximum profit you can get at that difficulty (which includes any lower difficulties).\nUse i,j counter to find the maximum difficulty each worker can take on. Since each difficulty is already pre-calculated to be the maximum profit, then just adding the profit should give you the total profit.\n\n```\nvar maxProfitAssignment = function(difficulty, profit, worker) {\n    const profitD = [];\n    \n    // create difficulty and profit array\n    for (let i = 0; i < difficulty.length; i++) {\n        profitD.push({d: difficulty[i], p: profit[i]});\n    }\n    \n    // sort on difficulty\n    profitD.sort((a, b) => a.d - b.d);\n    // sort worker\n    worker.sort((a, b) => a - b);\n    \n    \n    // process to the array to get maxProfit So Far\n    let maxSoFar = -Infinity;\n    for (let i = 0; i < profitD.length; i++) {\n        maxSoFar = Math.max(profitD[i].p, maxSoFar);\n        profitD[i].p = maxSoFar;\n    }\n    \n    \n    let i = 0;\n    let j = 0;\n    let total = 0;\n    while (i <= profitD.length && j < worker.length) {\n        // use the last profit and assign it to all the remaining workers\n        // can do this in another for loop\n        if (i === profitD.length) {\n            total += profitD[i - 1].p;\n            j++;\n            continue;\n        }\n          \n        const {p, d} = profitD[i];\n        // increment i if too difficult\n        if (d <= worker[j]) {\n            i++;\n        } else {\n            if (i - 1 >= 0) {\n                total += profitD[i - 1].p;\n            }\n            j++;\n        }\n    }\n    return total;\n};\n```
['Array', 'Sorting', 'JavaScript']