We want exactly elements. Define = optimal count when each element costs . is monotonically non-increasing in .
More elements used. Binary search: find smallest where . Or find where exactly. Subtlety: might jump (not hit every value). Handle ties carefully. Often we binary search and check both boundaries.