Greedy Method
Intuition\nThe key observation is that transactions where the cost is greater than the cashback are risky since we lose money, while transactions where the cash
# Intuition\nThe key observation is that transactions where the cost is greater than the cashback are risky since we lose money, while transactions where the cashback is greater than or equal to the cost are safe.\n\n# Approach\n1. Separate the transactions into two categories: risky transactions (where the cost is greater than the cashback) and safe transactions (where cashback is greater than or equal to the cost).\n2. For risky transactions, calculate the total money we would need to handle them. This is done by summing the difference between cost and cashback for each risky transaction.\n3. Track the maximum cashback from risky transactions since it reduces the initial money required.\n4. For safe transactions, simply track the maximum cost, as this is the minimum initial money needed if no risky transaction requires more.\n5. The final answer is the sum of the total money required for risky transactions and the maximum of either the largest cashback or the highest cost from safe transactions.\n\n# Complexity\n- Time complexity:\nThe algorithm processes each transaction once, so the time complexity is $$O(n)$$, where `n` is the number of transactions.\n\n- Space complexity:\nThe space complexity is $$O(1)$$ because we only use a fixed amount of extra space for tracking variables, regardless of the number of transactions.\n\n\n# Code\n```python3 []\nclass Solution:\n    def minimumMoney(self, transactions: List[List[int]]) -> int:\n        maxInNegDiff = 0\n        maxCashback = 0\n        minMoney = 0\n      \n        for cost,cashback in transactions:\n            if cashback >= cost:\n                maxInNegDiff = max(maxInNegDiff,cost)\n                continue\n            \n            minMoney += cost - cashback\n            maxCashback = max(maxCashback, cashback)\n            \n        \n        return minMoney + max(maxInNegDiff ,maxCashback)\n            \n\n\n\n            \n\n\n\n```
['Python3']