#C3283. Employee Sales and Top-K Queries

    ID: 46693 Type: Default 1000ms 256MiB

Employee Sales and Top-K Queries

Employee Sales and Top-K Queries

You are given E employees, numbered from 1 through E, and Q commands. Each command is one of the following types:

  • SALE x s: Increase the sales of employee x by an amount s.
  • RESET x: Reset the sales of employee x to zero.
  • TOP_K k: Query the top k employees with the highest sales. In case of ties, the employee with the smaller index is ranked higher.

Your task is to process these commands in order. For each TOP_K command, output a line containing the IDs of the top k employees, separated by a single space.

The ranking is determined by the following order: employees are sorted in descending order of their sales amounts; if two employees have the same sales amount, the one with the smaller employee ID comes first. Formally, if S[i] denotes the sales for employee i, then the ordering must satisfy $$ S[a] ≥ S[b] $$ with ties broken by smaller a.

Note: Input is provided via standard input and output should be printed to standard output.

inputFormat

The first line contains two integers E and Q, denoting the number of employees and the number of commands, respectively. The next Q lines each contain a command in one of the following formats:

  • SALE x s
  • RESET x
  • TOP_K k

Here, x and s are integers denoting the employee id and the sales amount, respectively, and k is the number of top employees to query.

outputFormat

For each TOP_K command, output a line containing the IDs of the top k employees (space-separated) based on the current sales amounts.

## sample
5 6
SALE 1 100
SALE 2 200
SALE 3 50
TOP_K 2
RESET 2
TOP_K 2
2 1

1 3

</p>