#Pyth, 64 bytes
M?smg-Gddr1hhS,GHG1Akd,QOgQQWQFNr1hhS,QkKg-QNNI<dKB-=dK)N=kN-=QN
M Lambda g(G,H)
? G If G truthy
s Sum
m Map
g Recursive call
-Gdd G-d,d
r Range
1 1 to
h +1
hS First element of sorted (does min)
,GH From G and H
1 Else 1
A Double assign
kd Vars k and d
, To vals
Q Q (evaled input)
O Randrange 0 till val
gQQ Call g(Q, Q)
WQ While Q is truthy
FN For N in
r Range
1 From one
h Till +1
hS,QK Min(Q,K)
Kg K=g(
-QN Q-N
N N
I<dK If d<k
B Break (implicit close paren)
-=dk Subtracts d-=k
) Close out for loop
N Prints N
=kN Set k=N
-=QN Subtracts Q-=N