You learned the Aliens Trick for "exactly " constraints:
Add penalty per item/segment to remove the dimension.
Binary search on to hit exactly items.
Verify convexity: marginal benefit must decrease.
Track counts during DP to guide binary search. You solved four problems: Building a Tall Barn (clearest convexity), Levels and Regions (standard partition), Gosha is Hunting (two constraints), and IOI 2016 Aliens (combined with CHT). This technique is rare but effective when it applies.