low
and high
to 0, which represent the sum of floor values and ceil values respectively.diff
to store the differences between ceil and floor rounding errors.low
and the ceil value to high
.
c. If the floor and ceil values are different, add the difference to diff
.low
is greater than target
or high
is less than target
, return -1
.diff
in descending order based on the difference between ceil and floor rounding errors.ceilN = target - low
.ceilN
prices and the floor rounding errors for the rest.