Company: Visa (Associate SW Engineer) off campus_17march
Difficulty: easy
Item Pricing with Minimum Previous Discount A market stall sells n items, and you must buy every one of them in the order they are listed. Item i has a listed price prices[i] . The stall runs an unusual discount scheme: The first item is bought at its full listed price. For every later item, the discount is the lowest listed price among all the items bought before it . A discount never turns into a refund: if the discount exceeds the listed price, the item is free — you pay 0 , never a negative amount. So for i > 0 you pay max(prices[i] - min(prices[0], prices[1], ..., prices[i-1]), 0) . Note that the discount is always taken from the listed prices of the earlier items, not from the amounts actually paid for them. An item that was handed over for free still counts with its listed price when later discounts are worked out. Report the total amount spent on all n items. Input Format The first line contains a single integer n , the number of items. Each of the next n lines contains a si