Sponsored
Use these hints if you're stuck. Try solving on your own first.
Use dynamic programming: the states are (i, m) for the answer of piles[i:] and that given m.
Solve with full IDE support and test cases