Hide

Problem B
Starfleet Distress Signal

/problems/starfleetdistresssignal/file/statement/en/img-0001.png
A “Star Trek”-inspired spaceship. Source: AI Generated using OpenAI’s ChatGPT

The USS Enterprise has intercepted distress signals from various planets in the Federation. Each signal contains a two-letter planet code and a distress level. Your task is to help Starfleet assess the distress levels for each planet by grouping them based on their planet code, calculating their total distress levels, and categorizing these totals into priority levels based on severity.

For each unique planet code, calculate the total distress level by summing up all distress signals associated with it. Then, classify the planets into the following priority levels based on their total distress levels:

  • Low Priority: 1 to 20

  • Medium Priority: 21 to 50

  • High Priority: 51 to 70

  • Emergency: 71 or higher

Finally, produce a report listing each planet’s priority level. The planets within each priority level should be sorted alphabetically by their planet code.

Input

The input begins with a single line containing an integer $n$ ($1 \leq n \leq 100$), the number of distress signals. The following $n$ lines each contain a two-letter uppercase planet code (e.g., EA for Earth, VX for Vulcan, etc) and a positive integer $d$ ($1 \leq d \leq 100$), representing the distress level.

Output

For each priority category (Low Priority, Medium Priority, High Priority, Emergency), print the category name followed by a colon (:). Print categories in increasing orders of priority.

Below each category, display the planet codes in alphabetical order. For each planet, print the code followed by a colon, a space (: ), and its total distress level in the format:

[Planet Code]: [Total Distress Level]

Include only priority categories that contain at least one planet.

Sample Input 1 Sample Output 1
8
EA 1
EA 50
VX 12
HS 73
VX 1
HS 10
GB 27
HS 100
Low Priority:  
VX: 13

Medium Priority:  
GB: 27

High Priority:  
EA: 51

Emergency: 
HS: 183
Sample Input 2 Sample Output 2
7
HS 11
VX 21
GB 17
VX 30
GB 19
GB 77
AX 19
Low Priority:
AX: 19
HS: 11

High Priority:
VX: 51

Emergency:
GB: 113

Please log in to submit a solution to this problem

Log in