Solution Minimum Initial Energy to Finish Tasks
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public function minimumEffort($tasks) {\n        $ans = 0;\n        $energy_left = 0;\n\n        usort($tasks, function($a, $b) {\n            return ($b[1] - $b[0]) - ($a[1] - $a[0]);\n        });\n\n        foreach ($tasks as $task) {\n            $actual = $task[0];\n            $minimum = $task[1];\n\n            if ($energy_left < $minimum) {\n                $ans += $minimum - $energy_left;\n                $energy_left = $minimum - $actual;\n            } else {\n                $energy_left -= $actual;\n            }\n        }\n\n        return $ans;\n    }\n}\n\n```
['PHP']