#C11869. Team Productivity Queries

    ID: 41232 Type: Default 1000ms 256MiB

Team Productivity Queries

Team Productivity Queries

You are given a list of k integers representing the productivity of k employees. You need to process q queries. There are two types of queries:

  • T: Output the sum of the top three productivity values among all employees. That is, if the three largest values in the list are \(a\), \(b\), and \(c\), then the answer is \(a + b + c\).
  • P i x: Update the productivity of the employee at the 1-indexed position i to x.

It is guaranteed that the number of employees k is at least 3. Process the queries in the order given and for each T query, print the computed team productivity.

inputFormat

The input is read from standard input (stdin) in the following format:

  • The first line contains two space-separated integers (k) and (q), where (k) is the number of employees and (q) is the number of queries.
  • The second line contains (k) space-separated integers representing the productivity of each employee.
  • The next (q) lines each contain a query. A query is either of the form "T" or "P i x", where i is the 1-indexed employee position and x is the new productivity value.

Note: There is at least one query of type "T".

outputFormat

For each query of type "T", output the sum of the top three productivities on a new line. The output should be written to standard output (stdout).## sample

5 3
5 3 8 2 7
T
P 2 10
T
20

25

</p>