Official algorithmic problem description and constraints.
Alice and Bob are playing a game in the shop. There are π items in the shop; each item has two parameters: ππ (item price for Alice) and ππ (item price for Bob).
Alice wants to choose a subset (possibly empty) of items and buy them. After that, Bob does the following:
Alice's profit is equal to βπβπππββπβπππ, where π is the set of items Bob buys from Alice, and π is the set of items Alice buys from the shop. In other words, Alice's profit is the difference between the amount Bob pays her and the amount she spends buying the items.
Alice wants to maximize her profit, Bob wants to minimize Alice's profit. Your task is to calculate Alice's profit if both Alice and Bob act optimally.
Detailed video explanations, mathematical intuition, and clean C++ implementation code.