099. Autobahn

Codeforces
IDCF10269099
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Autobahn You are about to drive on the Autobahn. You have several different cars, and you're trying to decide which one to take on the Autobahn. The different cars have differing fuel efficiencies, measured in miles per gallon (MPG), and the cars have different top speeds. You calculate a car's _score_ as its fuel efficiency (MPG) multiplied by its top speed. Given the list of possible cars, your task is to sort them by their score. The first line of input contains a single positive integer $n$: the number of cars. The next $n$ lines each contain the data for a car: the name of the car, its fuel efficiency in MPG, and its top speed. Output $n$ lines, each consisting of a car, sorted by their score as described above. Each line should be in the same format as its corresponding line in the input file. The car with the lowest score should appear first, and the car with the highest score should appear last. If two or more cars have equal scores, sort them alphabetically by the names of each car. ## Input The first line of input contains a single positive integer $n$: the number of cars. The next $n$ lines each contain the data for a car: the name of the car, its fuel efficiency in MPG, and its top speed. ## Output Output $n$ lines, each consisting of a car, sorted by their score as described above. Each line should be in the same format as its corresponding line in the input file. The car with the lowest score should appear first, and the car with the highest score should appear last. If two or more cars have equal scores, sort them alphabetically by the names of each car. [samples]
**Definitions** Let $ n \in \mathbb{Z}^+ $ be the number of cars. Let $ C = \{ (name_i, mpg_i, speed_i) \mid i \in \{1, \dots, n\} \} $ be the set of cars, where: - $ name_i \in \mathbb{S} $ is the car name (string), - $ mpg_i \in \mathbb{R}^+ $ is the fuel efficiency in miles per gallon, - $ speed_i \in \mathbb{R}^+ $ is the top speed. The score of car $ i $ is defined as: $$ s_i = mpg_i \cdot speed_i $$ **Constraints** 1. $ 1 \le n \le 10^5 $ (implied by typical problem constraints; not explicitly given but standard) 2. $ mpg_i > 0 $, $ speed_i > 0 $ for all $ i $ 3. Car names are non-empty strings (assumed alphanumeric or printable ASCII) **Objective** Sort the cars in ascending order of $ s_i $. If $ s_i = s_j $, sort alphabetically by $ name_i $ in ascending lexicographical order. Output the original input lines (name, mpg, speed) in the sorted order.
API Response (JSON)
{
  "problem": {
    "name": "099. Autobahn",
    "description": {
      "content": "Autobahn You are about to drive on the Autobahn. You have several different cars, and you're trying to decide which one to take on the Autobahn. The different cars have differing fuel efficiencies, m",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10269099"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Autobahn\n\nYou are about to drive on the Autobahn. You have several different cars, and you're trying to decide which one to take on the Autobahn. The different cars have differing fuel efficiencies, m...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ be the number of cars.  \nLet $ C = \\{ (name_i, mpg_i, speed_i) \\mid i \\in \\{1, \\dots, n\\} \\} $ be the set of cars, where:  \n- $ name_i \\in \\mathbb{S} $ is ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments