Short Sell
InterviewTime limit1sMemory limit512 MB
Given N daily prices and a daily interest K per 100 borrowed coins, pick a borrow day and a repay day to maximize profit.
- Level
Medium4 of 10
- Topics
- Array, Prefix sum, Greedy, Math
- Solved
- No attempts yet
Problem
Simone is learning to trade crypto currencies. Right now, she is looking into a new currency called CryptoKattis. A CryptoKattis can be used to improve your Kattis ranklist score without having to solve problems.
Simone, unlike most competitive programmers, is very perceptive of competition trends. She has lately noticed many coders talking about a new online judge called Doggo, and suspects that using the Kattis judge will soon fall out of fashion. This, of course, will cause the CryptoKattis to rapidly fall in value once demand fades.
To take advantage of this, Simone has performed very careful market research. This has allowed her to estimate the price of a CryptoKattis in dollars during the next days. She intends to use this data to perform a short sell. This means she will at some day borrow CryptoKattis from a bank, immediately selling the currency. At some other day, she must purchase the same amount of CryptoKattis to repay her loan. For every day between (and including) these two days, she must pay dollars in interest. What is the maximum profit Simone can make by carefully choosing when to borrow and repay the CryptoKattis?
Input
The first line of the input contains two integers and . is the number of days you know the CryptoKattis price of, and is the cost in dollars of borrowing CryptoKattis per day.
The next line contains integers separated by spaces. These are the CryptoKattis prices during the days. Each CryptoKattis price is between and dollars.
Output
Output a single decimal number; the maximum profit you can make performing a short sell. If you cannot make a profit no matter what short sell you make, output .