Stock Simulation
Time limit1sMemory limit1024 MB
Simulate buying, selling, and price changes across companies grouped by number, then print the cash and total liquidation value at each menu 6 or 7 query.
- Level
Easy3 of 10
- Topics
- Simulation, Hash map, Implementation
- Solved
- No attempts yet
Problem
Hayi lost money in the stock market again today. Yutil, who had watched Hayi keep losing money, gave Hayi a USB drive with a stock simulation program and suggested practicing with it.
Hayi got home and plugged the USB into the computer. When the program started, seven menus appeared.
- 1 : Buy shares of company . If Hayi cannot afford shares with the cash currently held, nothing is bought.
- 2 : Sell shares of company . If Hayi holds shares of company , and , nothing happens. If , all shares are sold.
- 3 : The stock price of company rises by won. If , the price falls by won.
- 4 : The stock prices of the companies in group rise by won. If , the prices fall by won.
- 5 : The stock prices of the companies in group rise by %. If , the prices fall by %.
- 6: Print the cash Hayi currently holds.
- 7: Print the total cash Hayi would have if all currently held shares were sold.
The program manual has the following details.
- At the start, Hayi holds no shares.
- Company names are case-sensitive.
- Shares are bought and sold in units of 10 won. For menu 5, the prices are updated by the rate first, and then the ones digit is truncated.
- At all times, the stock price of each company satisfies ().
- At all times, the total cash obtained by selling every share Hayi holds does not exceed won.
- In menu inputs 1, 2, and 3, is always a company listed on the market.
- In menu inputs 4 and 5, at least one company belongs to group .
- Menu 6 or 7 appears at least once.
Hayi started trying the program with various data. Then a problem appeared. When Hayi chose menu 6 or 7, the program should print the cash, but it printed only ???.
Hayi called Yutil and said the program had a problem. Yutil said that if Hayi gave all the input data, he would report the results for menu 6 or 7. However, Yutil was too busy building another program, so he asked whether you could handle this task instead. Let's help Yutil!
Input
The first line contains the number of listed companies , the cash Hayi holds , and the number of menu inputs , separated by spaces. (; ; )
From the second line through the next lines, each line contains the group number of a company, the company name , and the price of one share at the start of the simulation, separated by spaces. A company name is a string of up to 30 English letters, and no company name appears more than once. (; ; is a multiple of 10)
From the next line through the next lines, the menu inputs are given. (; ; ; ; is a multiple of 10)
All numbers in the input are integers.
Output
Print the results of menu 6 and menu 7 inputs, one per line.