Salma has been tracking the price of the Edyst company stock over a long time, collecting day by day data on what the Edyst stock value was on that day. Now that she has all this data, she wants to find out a way in which she could have made a profit buying and selling this stock. However, her father has restricted her to purchasing and holding only 1 unit of the stock at any given time, which means she cannot buy until she sells the unit stock that she already has. Write a program to help her find on which days she should have bought Edyst stock and on which day she should have sold it so that at the end of it all, she would make the most profit. For example, suppose she tracked the price for 7 days: [100, 180, 260, 310, 40, 535, 695]. To make the maximum profit, she should first buy on day 0, and sell on day 3. Again buy on day 4 and sell on day 6. This way, she makes a profit of (310-100) + (695-40) = 865. If Salma can't make any profit, print Can't make a profit! Input Format: First line is an integer N N integers follow in the second line. Output Format: Print the indexes of days on which to buy/sell as shown in the examples below. Else, print Can't make a profit!. Sample Input 1: 5 5 4 3 2 1 Output: Can't make a profit! Example Input: 6 1 5 3 6 7 8 Output: 0 1 2 5 This means that Salma should buy on day 0, sell on day 1. Then buy on day 2 and sell on day 5.
Answers
Answered by
0
Similar questions