HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Data Structures > problem:


50735 - Top M Products

Guest
• Review clarifications (1)

Volume problems

• 50694 - The Cheapest Flight
• 50996 - Checkers - the shortest path
• 50770 - Average Depth
• 50291 - Postfix Arithmetic Expressions
• 50775 - Balanced Parenthesis
• 50736 - Top N Donors - 2
• 50796 - KNN
• 50340 - Game 19
• 50735 - Top M Products
• 50697 - Base Stations
• 50383 - Noisy Mornings
• 50479 - Bit Compressor
• 50674 - Collecting Eggs
• 50486 - Problems and Programmers
• 50695 - Longest link between neurons
• 50411 - Sum of the Leaves
• 50677 - The Cottage

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Use Classes to solve the problem.

Semicolon Separated Product Info

Mr. Enea, sells building and sanitary materials. After selling the products he processes through his stock book. But, he wants to renew his system and to pass to a computerized system.

Question: Write a program that is going to read the stock information. And, show the most sold top m items.
Note: Use Quick sort to solve the problem.

Input specification
First, you will be given two numbers n and m, where

  • 1 < n ≤ 5000, that shows the number of items in the store
  • 1 < m ≤ 50, where m is the number of items to show on screen.
Then, in the following n lines you will be given semicolon separated product information. Every line contains the following information:
  1. Product ID: Every product is given a product ID on its entry. an integer number smaller than 10 million
  2. Product name: At most 40 chars string. It may contain any ASCII char ending with a semicolon.
  3. Product category: At most 40 chars string. It may contain any ASCII char ending with a semicolon.
  4. Entry price: a floating point number
  5. Sell price: a floating point number
  6. Amount sold: The number of items sold on different days. Space separated series of 5 integers

Output specification
Show

  • the Product ID
  • the total amount sold
of the top m items in decreasing order of amount sold.

Sample Input
  5 3
  1; Wall Mount Faucet 4"; Faucets; 21.50; 27.52; 8 8 3 17 2;
  2; Sharkbite Fittings 8"; Fittings; 9.11; 10.11; 13 4 21 23 11;
  3; Murano Vessel Lavatory - White; Vessels; 9.71; 12.73; 16 4 25 6 11;
  4; Barbed Fittings 7"; Fittings; 17.80; 19.94; 3 21 7 5 20;
  5; Contemporary Lever Handles; Shower Arms; 1.75; 2.14; 1 9 17 5 25;

Sample Output
  2 72
  3 62
  5 57

Output Explanation :
  Product 2 is the most sold product: 72 pieces of it has been sold. That is followed by the products 3 and 5.


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

www.contester.ru