You have a water dispenser that can dispense cold, warm, and hot water. Every second, you can either fill up 2 cups with different types of water, or
1 cup of any type of water.
You are given a 0-indexed integer array amount of length 3 where
amount[0], amount[1], and amount[2] denote the number of cold, warm, and hot water cups you need to fill respectively. Return theminimum number of seconds needed to fill up all the cups.
Input: amount =[1,4,2]Output: 4Explanation: One way to fill up the cups is:Second 1: Fill up a cold cup and a warm cup.Second 2: Fill up a warm cup and a hot cup.Second 3: Fill up a warm cup and a hot cup.Second 4: Fill up a warm cup.It can be proven that 4is the minimum number of seconds needed.
Input: amount =[5,4,4]Output: 7Explanation: One way to fill up the cups is:Second 1: Fill up a cold cup, and a hot cup.Second 2: Fill up a cold cup, and a warm cup.Second 3: Fill up a cold cup, and a warm cup.Second 4: Fill up a warm cup, and a hot cup.Second 5: Fill up a cold cup, and a hot cup.Second 6: Fill up a cold cup, and a warm cup.Second 7: Fill up a hot cup.
At each second, we can fill either two cups of different types or one cup of any type. To minimize the time, always fill the two largest remaining cup types together. The answer is the maximum of the largest cup count and the ceiling of half the total cups.