Sane's Monthly Algorithms Challenge: November 2008
You have illegally obtained some insider information about the projected
trend of a particular stock over the next
The information consists of
In the first Stock Market Challenge (July's SMAC Challenge), you were
attempting to avoid rousing suspicion with your
However, you will also need to pay a fixed commission rate to your broker on each transaction (every buy and every sell).
Using the stock's projection, determine the optimum times to buy then sell, and the resulting maximum profit. It is always guaranteed that a profit can be made.
Input Specification
On the first line is the integer
On the next
Output Specification
Output the maximum possible integer profit made in dollars, respectively.
Grading
For
Sample Input
24 30
1.00
1.05
1.06
1.07
1.03
0.98
0.99
1.01
1.09
1.14
1.13
1.12
1.11
1.10
1.09
1.08
1.07
1.06
1.05
1.04
1.03
1.02
1.01
1.00
Sample Output
110
Explanation of Sample Output
1) Buy 1000 at 1.00 for - 1000 - 30 = - $1030
4) Sell 1000 at 1.07 for + 1070 - 30 = + $1040
6) Buy 1000 at 0.98 for - 980 - 30 = - $1010
10) Sell 1000 at 1.14 for + 1140 - 30 = + $1110
-------
$110
Comments