Steven the monkey recently discovered something called the monkey stock market. He is given an array of
- Spend all his money to buy stock shares. He gains
shares, where denotes the amount of money he has. Then becomes . - Sell all the shares he currently has. He gains
dollars, where denotes the number of shares he has. Then becomes . - Don't take action.
Being an extremely popular monkey influencer, he can control the stock market by reordering the stock prices any way he wants.
However, he is an extremely busy monkey, so he hires you to help him determine an order of the prices such that if he acts optimally, he can maximize the amount of money he has by the end of the
Constraints
Input Specification
The first line contains the integer
The next line contains the
Output Specification
On the first line, output some optimal permutation of the original array. On the next line, output B
for buying, S
for selling, or E
for skipping. Remember that having shares is not the same as having money.
Note: Any valid output will be accepted.
Sample Input
3
4 2 2
Sample Output
2 2 4
BES
Explanation
Say we start with
Comments
O(N lg N), Java instead of Python, using faster input libraries, and still TLE. How can I shave off some more microseconds? 😒
string concatenation is O(N)
im not good w ad hoc is the optimal strat for the last 2 days to buy on the cheapest price, then sell on the highest price?
What is it with the Presentation Error?
My answer is in
complexity but is considered too slow... Is it because I code in Python ?
Steven 🤓 the monkey 🐒 on 👉👉 the 🙄 sigma ∑ male 😤🥵 grind 💪💪🏻💪🏼💪🏽💪🏾💪🏿 set 💸🤑💰💰💰