1
class Solution {
2
public:
3
int minimumRefill(vector<int> &plants, int capacityA, int capacityB) {
4
int n(plants.size()), res(0), aliceC(capacityA), bobC(capacityB), alice(0), bob(n - 1);
5

6
while (alice < bob) {
7
if (alice == bob) {
8
if (aliceC < plants[alice] and bobC < plants[bob]) res++;
9
break;
10
}
11
if (aliceC < plants[alice]) aliceC = capacityA, res++;
12
if (bobC < plants[bob]) bobC = capacityB, res++;
13
aliceC -= plants[alice++];
14
bobC -= plants[bob--];
15
}
16
return res;
17
}
18
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0