-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path02_Water_Bottles_II.cpp
More file actions
51 lines (35 loc) · 1.57 KB
/
Copy path02_Water_Bottles_II.cpp
File metadata and controls
51 lines (35 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// 3100. Water Bottles II
// You are given two integers numBottles and numExchange.
// numBottles represents the number of full water bottles that you initially have. In one operation, you can perform one of the following operations:
// Drink any number of full water bottles turning them into empty bottles.
// Exchange numExchange empty bottles with one full water bottle. Then, increase numExchange by one.
// Note that you cannot exchange multiple batches of empty bottles for the same value of numExchange. For example, if numBottles == 3 and numExchange == 1, you cannot exchange 3 empty water bottles for 3 full bottles.
// Return the maximum number of water bottles you can drink.
// Example 1:
// Input: numBottles = 13, numExchange = 6
// Output: 15
// Explanation: The table above shows the number of full water bottles, empty water bottles, the value of numExchange, and the number of bottles drunk.
// Example 2:
// Input: numBottles = 10, numExchange = 3
// Output: 13
// Explanation: The table above shows the number of full water bottles, empty water bottles, the value of numExchange, and the number of bottles drunk.
// Constraints:
// 1 <= numBottles <= 100
// 1 <= numExchange <= 100
class Solution
{
public:
int maxBottlesDrunk(int numBottles, int numExchange)
{
int bottleDrunk = numBottles;
int emptyBottles = numBottles;
while (emptyBottles >= numExchange)
{
emptyBottles -= numExchange;
numExchange++;
bottleDrunk++;
emptyBottles++;
}
return bottleDrunk;
}
};