Make Them Equal
MediumRating 1600Codeforces2-D Dynamic Programming
Approach hintTry it first, then revealHide
First find, for every value up to 1000, the fewest operations needed to reach it from 1; these numbers are all small. The task then becomes a 0/1 knapsack, and the budget k can be capped at the sum of all costs.