Sorting + Elegant C++ binary search
cpp\nusing ll = long long;\n\ntemplate <typename Predicate>\nll binary_search(ll low, ll high, Predicate&& predicate) {\n  if (low >= high) return low;\n  auto 
```cpp\nusing ll = long long;\n\ntemplate <typename Predicate>\nll binary_search(ll low, ll high, Predicate&& predicate) {\n  if (low >= high) return low;\n  auto const mid = low + (high - low) / 2;\n  if (predicate(mid)) {\n    return binary_search(mid + 1, high, predicate);\n  } else {\n    return binary_search(low, mid, predicate);\n  }\n}\n\nclass Solution {\n public:\n  long long minimumMoney(std::vector<std::vector<int>>& transactions) {\n    std::sort(std::begin(transactions), std::end(transactions),\n              [](auto const& a, auto const& b) {\n                auto const a_dip = std::min(-a[0], a[1] - a[0] - b[0]);\n                auto const b_dip = std::min(-b[0], b[1] - b[0] - a[0]);\n                if (a_dip == b_dip) return a[0] > b[0];\n                return a_dip < b_dip;\n              });\n    auto is_sufficient = [&](ll money) {\n      for (auto const& t : transactions) {\n        auto const cost = t[0];\n        auto const cashback = t[1];\n        if (money < cost) return false;\n        money += (-cost + cashback);\n      }\n      return true;\n    };\n    return binary_search(0, 1e14, std::not_fn(is_sufficient));\n  }\n};\n```
['C++']