#Q147. 「一本通 4.6 练习 2」郁闷的出纳员
「一本通 4.6 练习 2」郁闷的出纳员
Description
Original Source: NOI 2004
OIER Corporation is a large specialized software company with tens of thousands of employees. As a cashier, one of my tasks is to keep track of each employee's salary. This would be a decent job, but the frustrating part is that our boss is very capricious and frequently adjusts employees' salaries. If he's in a good mood, he might add the same amount to everyone's salary. Conversely, if he's in a bad mood, he might deduct the same amount from everyone's salary. I really don't know what else he does besides adjusting salaries.
Frequent salary adjustments are very annoying to employees, especially when salaries are deducted collectively. As soon as an employee finds that their salary has fallen below the lower bound specified in their contract, they will immediately leave the company in anger and never return. The lower salary bound is uniformly defined for all employees. Every time someone leaves the company, I have to delete their salary record from the computer. Similarly, whenever the company hires a new employee, I have to create a new salary record for them.
The boss often comes to me to inquire about salary information. He doesn't ask about specific employees but rather asks about the salary of the employee with the -th highest salary. Every time this happens, I have to perform a lengthy sorting of tens of thousands of employees and then give him the answer.
Now that you understand my job quite well, as you might have guessed, I'd like you to write a salary statistics program. It shouldn't be too difficult, right?
Input Format
The first line contains two non-negative integers, and , where represents the number of commands to follow, and represents the lower salary bound.
The next lines each represent a command. The command can be one of the following four types:
| Name | Format | Function |
|---|---|---|
| I command | I k |
Create a new salary record with an initial salary of . If an employee's initial salary is below the lower bound, they will leave immediately. |
| A command | A k |
Add to every employee's salary. |
| S command | S k |
Deduct from every employee's salary. |
| F command | F k |
Query the -th highest salary. |
For I, A, and S commands, is a non-negative integer. For F commands, is a positive integer.
Initially, it can be assumed that the company has no employees.
Output Format
The number of output lines should be equal to the number of F commands plus one.
For each F command, your program should output a line containing a single integer, which is the salary of the employee with the -th highest salary. If exceeds the current number of employees, output .
The last line of the output file should contain a single integer, representing the total number of employees who left the company (excluding those who left due to their initial salary being below the lower bound).
Sample 1
9 10
I 60
I 70
S 50
F 2
I 30
S 15
A 5
F 1
F 2
10
20
-1
2
Data Range and Hints
For all data, the number of I commands does not exceed , the total number of A and S commands does not exceed , and the number of F commands does not exceed .
The adjustment amount for each salary change does not exceed , and the salary of new employees does not exceed .