For each item at index i, find the first later item whose original price is less than or equal to prices[i]. Subtract that later price as a discount. If no such later item exists, keep the original price. Return the final prices in their original order. Discounts are always determined from the input prices.
Example 1:
Input: prices = [5,2,4]
Output: [3,2,4]Explanation: The first later price no greater than 5 is 2, so the first final price is 3. Neither 2 nor 4 has an eligible later price, giving [3,2,4].
Example 2:
Input: prices = [3,3]
Output: [0,3]Explanation: The second item discounts the first by 3, making its price 0. The last item has no discount, so the result is [0,3].
Example 3:
Input: prices = [1,2,4]
Output: [1,2,4]Explanation: Every later price is larger than the current one. No item gets a discount, so all prices stay unchanged.
Constraints:
1 <= prices.length <= 5001 <= prices[i] <= 1000