A group of friends is hanging out at a party. Seeing as it is very hot, everyone is trying to drink as much water as possible.
At the beginning of the party, each person gets an initially empty glass and will use the same glass for the duration of the party.
Everyone drinks water at a rate of one unit per second. There is a fixed amount of water available and everyone will refill their glass as soon as it is emptied. Refilling a glass before it is empty is not allowed. Refilling any glass takes one second, regardless of its capacity. Any number of people may refill at the same time, but if there is not enough water left for everyone to refill their glasses, those with lower-indexed glasses gain precedence.
Observing that the glasses are not all of the same size, you notice that, by asking for a particular glass, you can maximize the amount of water you end up drinking. Given an int **availableWater** and a int[] **capacities**, return the 0-based index of the glass you should choose to maximize the amount of water you drink, breaking ties in favor of lower-indexed glasses. |