[Python] Explanation with pictures, Greedy
Sorting is not needed, please see Lee\'s solution.\n\n\n\n\n\n\n\nLet\'s focus on the first half, the n transcations that cost > cashback.\n\n\n\nSince we will 
### Sorting is not needed, please see [Lee\'s solution](https://leetcode.com/problems/minimum-money-required-before-transactions/discuss/2588034/JavaC%2B%2BPython-Easy-and-Coincise).\n\n\n<br>\n<br>\n\n\n\nLet\'s focus on the first half, the `n` transcations that `cost > cashback`.\n\n![image](https://assets.leetcode.com/users/images/e969e8c8-c43f-45eb-9fd2-1ecb1fc77ecb_1663430455.5225406.png)\n\nSince we will finish all the `loss` transactions anyway with a specific starting budget.\nSuppose we have had an order with the maximum budget, regardless of the order of the first `n - 1` transactions, which transaction we shall do **last**? The one with the largest cashback.\n\n![image](https://assets.leetcode.com/users/images/2b19e330-0241-46dd-ab03-e71fd9ec1598_1663430461.0073833.png)\n\nOnce we finished the last transaction, we go for the **second last** one. Similarly, regardless of the order of the first `n - 2` transactions, we finish the one with the highest cashback last. \n\nSo on so forth, until we finish the order of all transactions.\n\nFor earning transactions, since the budget will monotonically increasing, we put the one with the maximum cost first. After finishing all `loss` transactions, our budget should be no less than the maximum cost.\n\n![image](https://assets.leetcode.com/users/images/0f2b2954-211e-4b65-b77f-87c464192f29_1663430467.404248.png)\n\n\n**python**\n\n```\ndef minimumMoney(self, A: List[List[int]]) -> int:\n        # Splist transcations into two groups and sort according to the order.\n        L, E = [a for a in A if a[0] > a[1]], [a for a in A if a[0] <= a[1]]\n        L.sort(key = lambda x:  x[1])\n        \n        # budget: minimum budget we have met.\n        # curr: current budget we have.\n        budget, curr = 0, 0\n        \n        for a, b in L:\n            curr -= a\n            budget = min(budget, curr)\n            curr += b\n        \n        if E:\n            curr -= max(e[0] for e in E)\n            budget = min(budget, curr)\n\n        return -budget\n\n```
[]