#C128. Interstellar Spacecraft Selection
Interstellar Spacecraft Selection
Interstellar Spacecraft Selection
You are tasked with selecting the optimal spacecraft for interstellar exploration missions. Each test dataset defines specific mission requirements and provides a list of available spacecraft. Your program should choose the spacecraft that meets the following conditions:
- The spacecraft's fuel consumption must be less than or equal to the fuel threshold, i.e., \(\text{fuel} \le F\).
- The spacecraft's speed must be greater than or equal to the speed threshold, i.e., \(\text{speed} \ge S\).
- The spacecraft's cargo capacity must be greater than or equal to the cargo threshold, i.e., \(\text{capacity} \ge C\).
If multiple spacecraft satisfy the above criteria, choose the one with the highest speed. In the event of a tie, select the spacecraft that appears first in the input. If no spacecraft meets all requirements, output NONE
.
inputFormat
The input is given via standard input (stdin) and consists of multiple datasets. Each dataset begins with a line containing four integers: F S C P, where:
- F is the fuel threshold,
- S is the speed threshold,
- C is the cargo capacity requirement,
- P is the number of spacecraft entries that follow.
Each of the next P lines contains a spacecraft's information in the format:
name fuel speed capacity
The input terminates with a line containing a single 0.
outputFormat
For each dataset, output the name of the selected spacecraft on a new line. If no spacecraft satisfies the requirements, output NONE
.
The output should be written to standard output (stdout).## sample
50 500 100 3
Explorer1 30 600 150
Voyager2 50 500 100
Pioneer3 60 550 120
40 600 200 3
Hawk1 35 700 300
Falcon9 45 650 250
Eagle5 50 600 200
60 700 150 3
Swift 55 750 200
Rapid 60 800 150
Lightning 65 780 170
0
Explorer1
Hawk1
Rapid
</p>