National Olympiad in Informatics, China, 2004
OIER Ltd. is a large specialization software company with tens of thousands of employees. Being one of its cashiers, one of my jobs is to work with each employee's salary. This is normally not a bad job, but what makes it depressing is that my boss can never make up his mind. He frequently adjusts his employee's wages. If he's in the mood, he might add a fixed amount to each employee's wage. Contrarily, if he's unhappy, he just might deduct a fixed amount from each employee's wage. We really don't even know what else he does besides adjusting wages all day long.
The frequent adjustment of wages makes employees very resentful, especially when it's a deduction. Once an employee discovers that their wage has fallen below the minimum promised wage in their contract, they will immediately leave the company in anger, never to return. The lower bound of each employee's wage is uniformly regulated. Whenever an employee leaves the company, we need to delete their records from the computer. Similarly, whenever the company hires a new employee, we have to create a new record for them.
The boss often comes over to inquire about the status of wages. He never asks me about the wages of any specific employee. Instead, he asks for the wage of the -th highest paid employee. Whenever this happens, I can't help but perform a long and tedious sorting of the tens of thousands of employees in order to finally report the answer to him.
Alright. Now you've learned enough about my job. Just as you probably guessed, I would like you to please write a program that manages the wage information of the employees. How does that sound? Not too difficult, right?
Input Specification
The first line contains two non-negative integers and , representing the number of commands and the minimum regulated wage in all the employees' contracts, respectively.
Each of the next lines contains a single command that is one of the four following types:
Name | Format | Description |
---|---|---|
Initialize | I k |
Create a record for a new employee, with an initial wage of . If the initial wage of an employee is lower than the minimum wage, then they will immediately leave the company. |
Add | A k |
Add to the wage of every employee in the company. |
Subtract | S k |
Subtract from the wage of every employee in the company. |
Find | F k |
Find out and report the wage of the -th highest paid employee. |
In each of the Initialize
, Add
, and Subtract
commands, will be a
non-negative integer. In Find
commands, will be a positive integer.
Assume that initially, there are no employees in the company.
Output Specification
The number of lines in the output is the number of Find
commands plus .
For each Find
command, your program must output one line containing a
single integer, the wage of the -th highest paid employee at that
time. If is greater than the number of employees in the company at
the time, then output .
The last line of output should contain a single integer - the total number of employees that have left the company.
Note that if an employee leaves immediately, they do not count towards the above counter.
Sample Input
9 10
I 60
I 70
S 50
F 2
I 30
S 15
A 5
F 1
F 2
Sample Output
10
20
-1
2
Constraints
- The number of Initialize commands will not exceed .
- The total number of Add and Subtract commands will not exceed .
- The number of Find commands will not exceed .
- For each wage adjustment, the amount adjusted will not exceed .
- A new employee's wage starting wage will not exceed .
Scoring
For each test case, your score out of 10 will be determined as follows:
- If there is an incorrect number of values in your output, then your score will be .
- Otherwise, your score will be calculated as follows:
- If for all Find commands you output the correct answer, and for the last value you also output the correct answer, then you will score points.
- If you correctly determine the answer to all Find commands, but not the number of employees that left, then you will score points.
- If you only determine the number of employees that left, then you will score points.
- Otherwise, your score will be points.
Problem translated to English by .
Comments