MINSTOCK - Minimum Stocks
Himanshu wants to invest into stock market and his friend Navneet helps him by providing him instruction for next N days.
Navneet gives Himanshu 3 types of instruction,
1 X Y There is a stock X available at price Y. Here X is a string and Y is an integer.
2 X Z The price of stock X has changed to Z. Here X is a string and Z is an integer.
3 BUY Buy the stock which has the lowest price.
You as a programmer, is given all the instructions of N days. Can you tell, which stock did Himanshu buy on which day. Print the output in same order as himanshu bought the stock. See sample Input and Output for Clarification.
At any point of time, there is atmost one stock of X. However, X can be made available to market again through another instruction of type 1.
All instructions are valid. i.e There is always some stock to buy having the minimum price of all. Also if the price of X has changed, then X is already known and hasn't been bought yet.
First line contains N. (1 ≤ N ≤ 106)
Next N lines, each of them contains an instruction of any of 3 types. (Look at instruction format above)
In any instruction, (X is a string of length upto 10 characters. All characters are from english alphabets, both small and capital ) , and (0 ≤ Y ≤ 109) and (0 ≤ Z ≤ 109) .
For each instruction of type 3, output two values X and Y. Where X is the name of Stock having minimum price and Y is the day on which it was bought.
1 ABC 32
1 XDC 54
1 XCD 32
1 ABC 12
2 XDC 10
On day 3, there is instruction to buy. There are two stocks available "XDC" and "ABC", since price of "ABC" is less, he buys it. After this "ABC" is not available in market anymore.
On day 7, there is instruction to buy. Of all stocks available, "XDC" has the least price and hence he buys "XDC".
Anyone getting WA. LOOK AT THIS.
Used same mapping .....got TLE in java and AC in cpp...........Nice question
got WA on test case 10...any suggestions?
I did not understand why the output for XCD is 7 in the example, not 10. There were no instructions in the provided input that set price of XCD to 7.
Nice question. @Author, please mention the possible characters of the string X in the problem description.
My submission #22355284 is giving wrong answer on test case 9. My solution is in Java.
My code is giving correct result in 2 other IDEs and it's still showing runtime error here :(