#2335
Minimum Amount of Time to Fill Cups
pupil · 385 · lc easy +24 · verified · 60.1% accepted · 764 likes · top 58%
Description
You have a water dispenser that fills cold, warm, and hot water. Each second you may either fill two cups of different types simultaneously, or fill one cup of any type.
You are given a 0-indexed integer array amount of length 3 where amount[0], amount[1], and amount[2] are the numbers of cold, warm, and hot cups to fill. Return the minimum time in seconds to fill all cups.
Example 1:
Input: amount = [1,4,2]
Output: 4
Explanation: 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 4 is the minimum number of seconds needed.
Example 2:
Input: amount = [5,4,4]
Output: 7
Explanation: 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.
Example 3:
Input: amount = [5,0,0]
Output: 5
Explanation: Every second, we fill up a cold cup.
Code
1
2
3