simple code,  Greedy+ logic  O(n)
->for passing any permutation, the min value should pass the worst case scenario\n->the transactions can be divided into two parts\n1-> cost>cashback   \n   In 
->for passing any permutation, the min value should pass the worst case scenario\n->the transactions can be divided into two parts\n1-> cost>cashback   \n   In this case we have to pay cost[i]-cashback[i] for each transaction\n   for the last transaction we have to pay the cost -cashback for all the previous transactions +cost for the last       cashback\n   This means that max cost is  sum(cost -cashback) +max(cashback)\n   2-> cost<cashback \n     for the worst case we have to make transactioin with the max cost at the beginning\n   3-> when both exist\n\t we have to make all positive(cost-cashback) transctions first\n\t Then the negative (cost- cashback)\n\t ALSO WE HAVE TO CHECK AT TRANSITION FROM POSITIVE TO NEGATIVE  \n\t sum(cost- cashback)-> this we calculate only for positive transactions \n\t it will be either sum(cost- cashback)+ max(positive transaction cashback) <-ie. till buying the last positive transaction\n\t or sum(cost- cashback)+ max(cost negative transactions)   <--ie. buying all positive transaction and then max cost transaction in the negative category\n\n```\n long long minimumMoney(vector<vector<int>>& tr) {\n        int n = tr.size();\n        int maxpos=0;\n        long long possum=0;\n        int maxcostneg=0;\n        for(int i= 0;i<n;i++){\n            if(tr[i][0]>tr[i][1]){\n                maxpos=max(tr[i][1],maxpos);\n                possum+= tr[i][0]-tr[i][1];\n            }\n            else maxcostneg=max(maxcostneg,tr[i][0]);\n        }\n        return max(maxpos,maxcostneg)+possum;\n        \n```
['Greedy']