Beats 100% Runtime and Memory for submissions
Intuition\nThe problem involves a series of transactions, each requiring a certain amount of money to start (cost), and providing some money back after the tran
# Intuition\nThe problem involves a series of transactions, each requiring a certain amount of money to start (`cost`), and providing some money back after the transaction (`cashback`). The goal is to determine the minimum initial amount of money required to complete all transactions without running out of money at any point.\n\nThe challenge is to handle transactions where the cost is higher than the cashback, as they are more likely to cause us to run out of money. We must prioritize these transactions in a way that minimizes the risk of running out of money. Sorting the transactions by cashback ensures we deal with the riskiest transactions first, while keeping track of the maximum money used.\n\n# Approach\n1. **Sort the transactions by cashback**: This ensures that we tackle the transactions with lower cashback first, as they are riskier and have a higher chance of leaving us with insufficient funds if done later.\n\n2. **Track money usage**: \n   - For each transaction:\n     - If the cashback is less than the cost (`cb < co`), this transaction is considered risky. We need to add the cost to the current amount of money used (`currused`) and update the `moneyUsed` to ensure it reflects the highest amount needed at any point in time.\n     - After completing the transaction, reduce `currused` by the cashback amount, simulating the money we receive back.\n   - If the cashback is greater than or equal to the cost (`cb >= co`), it is a safer transaction. We only need to keep track of the maximum cost of these transactions (`maxxOfOther`) to ensure we have enough money to handle them.\n\n3. **Final Calculation**: \n   - The answer is the maximum of:\n     - `currused + maxxOfOther`: which ensures we have enough initial money to handle the safest transaction.\n     - `moneyUsed`: which reflects the highest amount of money required during the riskiest transactions.\n\n# Complexity\n- **Time complexity**:  \n  The sorting step dominates the complexity, so the time complexity is $$O(n \\log n)$$ where $$n$$ is the number of transactions.\n\n- **Space complexity**:  \n  The space complexity is $$O(1)$$ because we are using a constant amount of extra space, regardless of the input size.\n\n# Code\n```python3 []\nclass Solution:\n    def minimumMoney(self, transactions: List[List[int]]) -> int:\n        transactions = sorted(transactions, key=lambda i:i[1])\n        # maxuptonow = [0 for i in len(transactions)]\n        moneyUsed=0\n        currused=0\n        maxxOfOther=0\n        for co,cb in transactions:\n            if cb<co:\n                currused += co\n                moneyUsed = max(moneyUsed,currused)\n                currused-=cb\n            else:\n                maxxOfOther=max(maxxOfOther,co)\n        return max(currused+maxxOfOther, moneyUsed)\n```
['Python3']