You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('') and can be up to 35 characters long.
Lothar Buchholz
30543abaf9

3 years ago  

.idea  3 years ago  
doc  3 years ago  
gradle/wrapper  3 years ago  
src  3 years ago  
.gitignore  3 years ago  
README.md  3 years ago  
build.gradle  3 years ago  
gradlew  3 years ago  
gradlew.bat  3 years ago  
settings.gradle  3 years ago 
README.md
Buy and Sell ntimes
Goal
Given is the pricedevelopment of an arbitrary stock.
Suppose you have perfect knowledge and are able to buy and sell the stock multiple times. Write an algorithm that outputs the maximum profit that can be made by exactly n sales.
 The pricedevelopment is given for an arbitrary number of days.
 A stock can only be sold on the next day.
 Stockprices are given as integers
 Each buy must be made on another date after the previous sale
Input
A blankseparated array of numbers.
The first number is the number of sales allowed.
All following numbers are stockprices.
Each position symbolises the stockprice of a given day.
Output
The maximum profit that can be made within that period by n
sales.
Constraints
 2 <=
n
<= 10  2 *
n
<=days with stockprices
<= 50  1 <=
stockprice
<= 2,147,483,647
Example
Input:
3 12 11 13 9 12 8 14 13 15
where n
is 3
Output:
12