Sort N games by satisfaction-to-price ratio, then by lower price, then by game number, and print the first K game numbers.
Medium4SortingMathImplementationArrayInterviewNo attempts yetTime limit1sMemory limit512 MBJunseo 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 K 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.
Read the input from standard input. The first line has the number of games N on Smog and the number of games K that Junseo buys, separated by a space. (1≤N≤1000, 1≤K≤N)
Each of the next N lines has one game record i, c, h separated by spaces, where i is the game number, c is the price and h is the satisfaction. (1≤i≤N, 1≤c,h≤108) Every number from 1 to N appears exactly once, and the records are not necessarily given in number order.
Write the output to standard output. Print K 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 K games are bought. Sort all N games by it and the first K of them are the answer.