Alice and Bob want to water plants[i] units of water.
Alice starts at plant capacityA units of water, and Bob carries a can with a capacity of capacityB units of water. Both cans are completely full at the start.
They water the plants according to the following process:
Alice waters from left to right, and Bob waters from right to left.
If a person has enough water to satisfy the current plant, they water it using that amount.
If a person does not have enough water to satisfy the current plant, they completely refill their can to its full capacity first and then water the plant.
If Alice and Bob meet at the same plant:
The person with more remaining water in their can waters the plant.
If both have an equal amount of water, Alice waters it.
If the designated person does not have enough water, they refill their can before watering.
Return the total number of times Alice and Bob must refill their watering cans to water all the plants.
Constraints:
n == plants.length
plants[i]
plants[i]capacityA, capacityB
Alice and Bob want to water plants[i] units of water.
Alice starts at plant capacityA units of water, and Bob carries a can with a capacity of capacityB units of water. Both cans are completely full at the start.
They water the plants according to the following process:
Alice waters from left to right, and Bob waters from right to left.
If a person has enough water to satisfy the current plant, they water it using that amount.
If a person does not have enough water to satisfy the current plant, they completely refill their can to its full capacity first and then water the plant.
If Alice and Bob meet at the same plant:
The person with more remaining water in their can waters the plant.
If both have an equal amount of water, Alice waters it.
If the designated person does not have enough water, they refill their can before watering.
Return the total number of times Alice and Bob must refill their watering cans to water all the plants.
Constraints:
n == plants.length
plants[i]
plants[i]capacityA, capacityB