Approach hintTry it first, then revealHide
Prefix sums of the pile sizes give the last label in each pile; the pile holding a label is the first prefix sum not less than it, found with lower_bound.
Prefix sums of the pile sizes give the last label in each pile; the pile holding a label is the first prefix sum not less than it, found with lower_bound.