A monitoring station keeps a roster of sensor nodes deployed across a facility. Each node has a unique numeric ID, a short text label, a status tag describing its current condition, and a reliability score. For a maintenance report, the station wants to list only the nodes whose ID is odd and whose status is anything other than faulty, ordered from the highest reliability score to the lowest. When two qualifying nodes share the same score, list the one with the smaller ID first.
Given the full roster, print the qualifying nodes in the required order.
Line 1: a single integer n, the number of sensor nodes.
Each of the next n lines contains four space-separated values describing one node: nodeId label status score, where nodeId is a positive integer (all IDs are distinct), label and status are non-empty tokens of lowercase letters and digits (no spaces) of length at most 20, and score is an integer.
Print one line per qualifying node (odd nodeId and status not equal to faulty), each formatted as nodeId label status score, sorted by score descending and, for ties, by nodeId ascending. If no node qualifies, print nothing.
Example 1
Input
6 1 sensorA active 80 2 sensorB active 90 3 sensorC faulty 95 4 sensorD idle 70 5 sensorE active 85 6 sensorF active 60
Expected
5 sensorE active 85 1 sensorA active 80
Explanation
Odd IDs are 1, 3, and 5. Node 3 is excluded because its status is 'faulty'. That leaves node 1 (score 80) and node 5 (score 85). Sorted by score descending, node 5 comes first, then node 1.
Example 2
Input
4 1 alpha idle 50 2 beta active 99 3 gamma active 50 4 delta faulty 100
Expected
1 alpha idle 50 3 gamma active 50
Explanation
Odd IDs are 1 and 3; neither is faulty, so both qualify. Both have score 50, a tie, so the tie-break by ascending nodeId puts node 1 before node 3.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →