BigBull

0

0 votes
Problem

You are given an array prices of size N where prices[i] is the price of a given stock on the ith day.

Find the maximum profit you can achieve. You may complete most K transactions.

For every transaction, you will be charged a stockbroker fee, C.

Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).

 

Constraints:

0 <= K <= 100

0 <= C <= 1000

0 <= prices.length <= 1000

0 <= prices[i] <= 1000

 

Input

Input is given from Standard Input in the following format:

N K C

a1 a2 ..... aN

Output

Print the maximum profit.

 

Sample Input
6 2 1
3 2 6 5 0 3
Sample Output
5
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Buy on day 2 (price = 2) and sell on day 3 (price = 6), profit = 6-2 = 4. Then buy on day 5 (price = 0) and sell on day 6 (price = 3), profit = 3-0 = 3.(finally 1+1 = 2 will be charged for two transactions)

Editor Image

?