STOP USING MONEY
InterviewTime limit1sMemory limit512 MB
Sort N games by satisfaction-to-price ratio, then by lower price, then by game number, and print the first K game numbers.
- Level
Medium4 of 10
- Topics
- Sorting, Math, Implementation, Array
- Solved
- No attempts yet
Problem
Junseo likes games. He found an online store called Smog that sells games and lets a buyer re-download any purchased game at any time. Junseo thinks of himself as someone who knows how to enjoy things, so he would rather play many games a little than one game for a long time. Buying every game costs more money than he has. For each game he read the reviews and the details, then wrote down how much satisfaction he expects to get from it. Junseo now wants to pick the games with the best value for money, where value for money is satisfaction per unit of price, that is, satisfaction divided by price. He did not want to do the arithmetic by hand or write the program himself, so he asked you to write it. Given the list of games, print the numbers of the games Junseo buys, in the order defined below.
Input
Read the input from standard input. The first line has the number of games on Smog and the number of games that Junseo buys, separated by a space. (, )
Each of the next lines has one game record , , separated by spaces, where is the game number, is the price and is the satisfaction. (, ) Every number from to appears exactly once, and the records are not necessarily given in number order.
Output
Write the output to standard output. Print game numbers, one per line, starting with the best value for money. Games with equal value for money are ordered by ascending price, and games with equal value for money and equal price are ordered by ascending number.
That order also decides which games are bought. Sort all games by it and the first of them are the answer.