you want water n plant garden watering the plant arrange row label 0 n 1 leave right ith plant locate x There river x 1 refill watering atEach plant need specific water you water plant follow waywater plant order leave rightafter water current plant water completely water plant return river fully refill watering canyou refill watering earlyyou initially river ie x 1 it take step unit xaxisgiven 0indexe integer array plant n integer plantsi water ith plant need integer capacity represent watering capacity return number step need water plant Example 1input plant 2233 capacity 5output 14explanation Start river water Walk plant 0 1 step water watering 3 unit water Walk plant 1 1 step water Watering 1 unit water since completely water plant 2 walk river refill 2 step Walk plant 2 3 step water watering 2 unit water since completely water plant 3 walk river refill 3 step Walk plant 3 4 step water itSteps need 1 1 2 3 3 4 14example 2input plant 111423 capacity 4Output 30explanation Start river water Water plant 0 1 2 3 step return river 3 step water plant 3 4 step return river 4 step water plant 4 5 step return river 5 step water plant 5 6 stepsstep need 3 3 4 4 5 5 6 30example 3input plant 7777777 capacity 8Output 49explanation you refill water plantstep need 1 1 2 2 3 3 4 4 5 5 6 6 7 49 Constraintsn plantslength1 n 10001 plantsi 106maxplantsi capacity 109