You're working as a financial analyst and need to adjust a list of prices to meet an exact budget target. Given an array of decimal prices [p1, p2, ..., pn] and a target sum, you must round each price to its nearest integer (either floor or ceiling) such that the total equals the target.
Your goal: Find the rounding strategy that minimizes the total rounding error while achieving the exact target sum.
The rounding error for each price is |rounded_price - original_price|. You want to minimize the sum of all rounding errors.
Return: The minimum total rounding error as a string with exactly 3 decimal places, or "-1" if it's impossible to reach the target.
Example: If prices = [0.7, 2.3, 4.9] and target = 8, you could round to [1, 2, 5] with total error = 0.3 + 0.3 + 0.1 = 0.700
Input & Output
Constraints
- 1 โค prices.length โค 103
- 0 โค prices[i] โค 104
- 0 โค target โค 107
- Each price has at most 3 digits after decimal point