CEN254_PRE2x2 |
Старт: 10.июня.2017 в 10:03:00
Финиш: 10.июня.2017 в 11:00:00
Турнир завершён!
• Турнирная таблица
|
|
Лимит времени 2000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб. Question by Ibrahim Mesecan.
Most valueable stock items
Question:
You are buying and selling items in the stock market.
And, you keep your operations in a database (or in a
file). Write a program
that reads a list of stock market operations, then
prints most valueable (m) stock items.
Input specification:
At the beginning, you will be given two integers:
the number of operations (n) and the number of items (m)
to show.
Each of the following n lines will have four information
- Item code: a string not more than 12 chars
- Buying or selling: a char (B or S, no other char will be given)
- The number of items to process (buy or sell): an integer between 1 and 200
- Unit price: a floating point number not greater than 1,000
(unit price to buy or sell this item)
where 1 ≤ m ≤ n ≤ 35,000,
item codes are string
containing only 26 English uppercase or lowercase chars.
Output specification:
Show (m) most valueable stock items according to their unit prices.
If there are several items with the same unit price (absolute difference
is less than 0.0001), show the items in ascending order according
their symbols. Note: You need to use an efficient
mapping algorithm for this question, like AVL trees or Java TreeMap.
Sample Input
6 2
ASYI B 20 8.90
LSUV B 13 5.60
ANPFF B 4 8.20
ASYI S 13 8.80
ANPFF S 3 0.20
ASYI B 18 7.30
|
Sample Output
ANPFF
ASYI
|
Explanation:
There are 6 operations. And the top 2 items (according to the unit price)
has been asked.
- Symbol LSUV has only one operation, so its unit price is 5.60$,
- ASYI has been bought twice and sold once,
(20*8.90 + 18*7.30 -
13*8.80) with a total price of 195. Totally, 38 lots bought and
13 lots sold. So, 25 lots remained with a total price of 195. Then the unit
price is 7.8$.
- ANPFF has been bought once and sold once,
(4*8.20 - 3*0.20)
with a total price of 32.2. Only 1 lot remains, thus the unit price is
32.2$
Thus, the top two items are ANPFF and ASYI.
Для отправки решений необходимо выполнить вход.
|