#K44417. Filter and Sort Employees by Salary
Filter and Sort Employees by Salary
Filter and Sort Employees by Salary
You are given a list of employees and a salary threshold. Each employee is described by three values: an ID (an integer), a name (a string), and a salary (an integer). Your task is to filter the list and output only those employees whose salary is at least the given threshold. The filtered employees must be sorted primarily in descending order of salary. If two or more employees have the same salary, they should be sorted in ascending order of their ID.
Specifically, given an integer n
representing the number of employees, an integer t
representing the salary threshold, followed by n
lines, where each line contains an employee's ID, name, and salary separated by spaces, you need to output the filtered and sorted list. Each matching employee should be printed on a new line in the format:
If no employee matches the criteria, output nothing.
inputFormat
The first line of the input contains an integer n
, the number of employees.
The second line contains an integer t
, the salary threshold.
This is followed by n
lines, each containing three values separated by spaces:
ID
(integer)Name
(string)Salary
(integer)
outputFormat
For each employee that meets the condition (Salary ≥ t
), print a line with their details in the format:
The employees must be printed in descending order by salary. If multiple employees have the same salary, they should be printed in ascending order by their ID.
If no employee satisfies the condition, output nothing.
## sample5
6000
1 Alice 5000
2 Bob 3000
3 Charlie 7000
4 David 7000
5 Eve 4000
3 Charlie 7000
4 David 7000
</p>