ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Разделы > Linear Data Structures: Arrays > задача:


51141 - Most valuable stock items

Гость
• Вопросы к жюри (1)

Задачи раздела

• 50442 - Polynomial Addition
• 51015 - Student Scholarships
• 50982 - A thief in labyrinth
• 51091 - Guess the number - 1
• 51008 - Sum of Regional Maxes
• 50989 - Rectangles and Points
• 51020 - Number of nodes removed
• 50932 - Shifting rows and columns
• 51141 - Most valuable stock items
• 51014 - Nine Men's Morris game
• 51019 - Finding the hidden message
• 50497 - Falling Bricks - Revisited
• 50933 - Sum of the Biggest Neighbors
• 51100 - Minimum time to exit building
• 50444 - n digit kth number divisible...
• 50865 - Apartment Building Adminis...
• 51089 - Multiply a row and add it to ...

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 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.



Для отправки решений необходимо выполнить вход.

www.contester.ru