CCC '10 S1 - Computer Purchase

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 64M

Problem type
Canadian Computing Competition: 2010 Stage 1, Senior #1

In order to increase your performance on the ABC (Another Buying Contest), you decide that you need a new computer. When determining which computer to buy, you narrow your search categories to:

  • RAM (in gigabytes), denoted as R;
  • CPU speed (in megahertz), denoted as S;
  • disk drive space (in gigabytes), denoted as D.

You perform some analysis and determine that the most preferred machine is the machine that has the largest value of the formula 2R + 3S + D.

Your task is to read a given list of computers and output the top two computers in order of preference, from highest preference to lowest preference.

Input Specification

The first line of input will be an integer n (0 \le n \le 10\,000). Each of the remaining n lines of input will contain a computer specification. A computer specification is of the form:

  • computer name (a string of less than 20 characters)
  • the RAM available (an integer R with 1 \le R \le 128)
  • the CPU speed (an integer S with 1 \le S \le 4000)
  • the disk drive space (an integer D with 1 \le D \le 3000)

There is one space between the name, RAM, CPU speed and disk drive space on each line.

Output Specification

The output is the name of the top two preferred computers, one name per line, sorted in decreasing order of preference. If there is a tie in the rankings, pick the computer(s) whose name(s) are lexicographically smallest (i.e., Apple is smaller than Dell). If there is only one computer, output that computer on one line (i.e., do not print it twice).

Sample Input

ABC 13 22 1
DEF 10 20 30
GHI 11 2 2
JKL 20 20 20

Output for Sample Input


Explanation of Output for Sample Input

Computer ABC has a computed value of 93. Computer DEF has a computed value of 110. Computer GHI has a computed value of 30. Computer JKL has a computed value of 120. Therefore, computer JKL is the most preferred, followed by computer DEF.


  • 0
    ThatGuyOnTheStreet  commented on Nov. 11, 2018, 3:57 p.m.

    Two of the test cases are the same; 5 and 6.

  • 0
    AidanB  commented on Oct. 12, 2018, 1:45 p.m.

    Keep getting WA for test case 1? Anyone know why?

  • 0
    UniteeX  commented on Jan. 21, 2018, 3:08 p.m. edited


  • -2
    bobhob314  commented on Dec. 24, 2014, 9:34 p.m.
    For Test Case 8

    For Test Case 8, no spoilers but I know what the test case is, and there is no specification on what to print for that input number. What is the output supposed to be? Thanks, bob

    • 2
      FatalEagle  commented on Dec. 24, 2014, 9:40 p.m.

      You don't have to print anything if n = 0

      • 8
        zys5945  commented on Oct. 1, 2015, 11:47 a.m.

        Should change the problem description from 0 < N < 10000 to 0 <= N < 10000