Pokemon Trading
Time limit0.3sMemory limit4 MB
With a fixed budget, buy on one day and sell on a later day to maximize profit; report the best result rounded to two decimals.
Problem
Jim likes Pokemon and plays every game they appear in. The game he plays now is a trading game. Jim already knows the price of a Pokemon on each of the next days. The type does not matter, so a single price applies to every Pokemon on a given day.
Jim starts with a fixed amount of money. He picks one day and spends all of his money buying Pokemon on that day, then picks a later day and sells all of them. Fractional Pokemon can be bought. The selling day must come after the buying day.
Find the largest profit Jim can get. If every choice loses money, find the smallest loss.
Input
The first line contains the amount of money Jim has.
The second line contains the number of days . ()
Starting from the third line, prices are given in day order, separated by spaces.
The money and every price are positive real numbers of at most with at most 6 digits after the decimal point.
Output
Print the maximum profit on the first line, with 2 digits after the decimal point. The value is negative when Jim loses money.
Rounding goes away from zero. That is, becomes 0.01, becomes 0.00, becomes -0.01, and becomes -0.00. When the profit is less than but its rounded magnitude is , print -0.00.