Brain-Flak, 153 bytes
{(({})<>[({})])(({}({}))[({}[{}])])<>(([{}]({})))([({}<(())>)](<>)){({}())<>}{}{((<{}>))<>{}}{}<>{}{{}({}<>{}())((<>))}{}{}}{}<>{}([]){{}({}<>)<>([])}<> This includes +1 for the -r flag.
#While True { #Magic#Push the last value left in the array minus the counter onto the alternate stack (({})<>[({})]) #Swap#Put the counter back on top of the alternate stack (({}({}))[({}[{}])]) #Toggle <> Find#Find the difference between the last two inputs left on the stackarray (([{}]({}))) Greater#Greater than or equal to 0? ([({}<(())>)](<>)){({}())<>}{}{((<{}>))<>{}}{}<>{} #If So: { #Pop the truthy/falsy value {} #Increment the counter by the difference between elements +1 ({}<>{}()) #Push two falsys ((<>)) #Endwhile } #Pop the two falsys {}{} #Endwhile } #Pop the falsy {} #Toggle back <> #Pop the counter #Reverse the stack {} ([]){{}({}<>)<>([])}<>