yes bro in this question we are given ‘n’ boxes and capacity of those boxes is given. we choose any index ‘L’ and from start to that index (from 1 to ‘L’) we put 1 token in each box.if capacity of any box is filled we choose index of box before that which is not full.

let us understand with example clearly

you are given 3 boxe or ‘n’=3

capacity of boxes is 2 ,1 and 3

we choose any index between 1 and 3 ,i start ‘L’ from 3(last index) because i can put 1 token in each box upto index 3(last index) .

now capacity of of boxes is 1,0,2 ,we will use one variable to count total tokens uses

here total 3 tokens used 1 in each box so tot=3;

as we can see at 2nd index value becomes 0 ,now we cannot choose any index greater than equal to 2 .

so we will choose index L=1 as it is non zero and now tokens capacity is

0,0,2 and tot=3+1=4

now we can’t choose any index greater than equal to 1 so we got our answer that is 4