Alice Bob want water n plant garden the plant arrange row label 0 n 1 leave right ith plant locate x ieach plant need specific water Alice Bob water initially they water plant follow wayalice water plant order leave right start 0th plant Bob water plant order right leave start n 1th plant they begin water plant simultaneouslyIt take time water plant regardless water needsAliceBob water plant fully water otherwise refill instantaneously water plantin case Alice Bob reach plant water currently hisher watering water plant if water Alice water plantGiven 0indexe integer array plant n integer plantsi water ith plant need integer capacityA capacityB represent capacity Alices Bobs watering can respectively return number time refill water plant example 1input plant 2233 capacitya 5 capacityB 5output 1explanation Initially Alice Bob 5 unit water watering can Alice water plant 0 Bob water plant 3 Alice Bob 3 unit 2 unit water respectively Alice water plant 1 water Bob water plant 2 refill water itso total number time refill water plant 0 0 1 0 1example 2input plant 2233 capacitya 3 capacityB 4output 2explanation Initially Alice Bob 3 unit 4 unit water watering can respectively Alice water plant 0 Bob water plant 3 Alice Bob 1 unit water need water plant 1 2 respectively since water current plant refill can water plantsSo total number time refill water plant 0 1 1 0 2example 3input plant 5 capacitya 10 capacityb 8output 0explanation There plant alice water 10 unit water Bobs 8 unit since Alice water water plantso total number time refill 0 Constraintsn plantslength1 n 1051 plantsi 106maxplantsi capacityA capacityB 109