[Java/C++/Python] Sort, and some story
Intuition\nNeed to sort by minimum - actual\n\n\n# Explanation\nWe have n investor,\neach investor can invest actual energy,\nand he think your company have min
# Intuition\nNeed to sort by `minimum - actual`\n<br>\n\n# Explanation\nWe have `n` investor,\neach investor can invest `actual` energy,\nand he think your company have `minimum` value.\n\nIf you already have at least `minimum - actual` energy,\nthe investory will invest you `actual` energy.\n\nAssuming you get all investment,\nhow many energy you have at least in the end?\n\nWe sort by the energy required `minimum - actual`.\n`res` is our current energy.\nEach round we will get energy `a` and reach `max(res + a, m)`.\nReturn directly `res` in the end.\n<br>\n\n# Continue the story\nThe following explanation is from @kaiwensun, vote for him.\n\n`minimum - actual` is the "bar" of an investor.\nif your company doesn\'t already have at least `minimum - actual` energy/value\nwhen the investor is assessing your company,\nyou don\'t meet the investor\'s bar.\nThey don\'t want to invest to you.\n\nBut don\'t worry, you can pay some extra energy/money\nfrom your own pocket to reach `minimum - actual` and meet the bar,\nthen the investor will invest actual energy.\n\nEventually, every investor will invest actual to you.\nYou want to pay as little out-of-pocket energy/money as possible.\n\nSo you want your company\'s energy/value to be as high as possible\nbefore visiting an investor to let it asses your company.\n\nIn other words, you want to first visit those investors whose bar is lower.\n\nSo we sort by investors by their "bar",\ni.e. by their `minimum - actual`.\n<br>\n\n# Complexity\nTime `O(sort)`\nSpace `O(sort)`\n<br>\n\n**Java**\n```java\n    public int minimumEffort(int[][] A) {\n        int res = 0;\n        Arrays.sort(A, (a1, a2) -> (a1[1] - a1[0]) - (a2[1] - a2[0]));\n        for (int[] a : A) {\n            res = Math.max(res + a[0], a[1]);\n        }\n        return res;\n    }\n```\n**C++**\n```cpp\n    int minimumEffort(vector<vector<int>>& A) {\n        int res = 0;\n        for (auto &a : A)\n            a[0] = a[1] - a[0];\n        sort(A.begin(), A.end());\n        for (auto &a : A)\n            res = max(res + a[1] - a[0], a[1]);\n        return res;\n    }\n```\n**Python:**\n```py\n    def minimumEffort(self, A):\n        A.sort(key=lambda a: a[1] - a[0])\n        res = 0\n        for a, m in A:\n            res = max(res + a, m)\n        return res\n```\n
[]