tray_size and never starts a new tray before the previous one is sold out. Several parties of customers will come today: groups[i] is the size of the i-th party. Every customer takes exactly one bun, and a party is served completely before the next one.
A party is happy if its first customer gets a bun from a fresh tray, meaning nothing was left over from earlier customers.
You choose the order in which parties are served. Return the largest possible number of happy parties.tray_size=4, groups=[4, 1, 3, 2, 2] → 3
Order them 4, 1, 3, 2, 2: the group of 4 takes a whole tray, 1 + 3 empties the next one, and so does 2 + 2. The groups of 4, 1 and the first 2 are happy, 3 in total.
tray_size=5, groups=[3, 3, 3] → 1
Only the first group starts on a fresh tray: 2 buns are left after it, and 4 after the second group.
tray_size=1, groups=[7, 2, 5] → 3
tray_size=4, groups=[4, 1, 3, 2, 2]
3
Run checks the first 3 tests in your browser. Submit checks all 127 tests on the server, hidden ones included.